"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const key_provider_1 = require("../walls/06-memory/privacy/key-provider");
const key_provider_file_1 = require("../walls/06-memory/privacy/key-provider-file");
const key_migration_1 = require("../walls/06-memory/privacy/key-migration");
describe('Key Provider', () => {
    it('detectOS returns a valid OS type', () => {
        const os = (0, key_provider_1.detectOS)();
        expect(['windows', 'macos', 'linux', 'unknown']).toContain(os);
    });
    it('deriveMachineKey returns 32-byte buffer', () => {
        const key = (0, key_provider_1.deriveMachineKey)();
        expect(key).toBeInstanceOf(Buffer);
        expect(key.length).toBe(32);
    });
    it('deriveMachineKey is deterministic', () => {
        const key1 = (0, key_provider_1.deriveMachineKey)();
        const key2 = (0, key_provider_1.deriveMachineKey)();
        expect(key1.equals(key2)).toBe(true);
    });
    it('getKeyProviderInfo returns provider info', () => {
        const info = (0, key_provider_1.getKeyProviderInfo)();
        expect(info.os).toBeDefined();
        expect(typeof info.name).toBe('string');
        expect(typeof info.available).toBe('boolean');
    });
    it('FileKeyProvider can set and get keys', () => {
        const provider = new key_provider_file_1.FileKeyProvider();
        if (!provider.isAvailable())
            return;
        const testKey = Buffer.alloc(32, 0xab);
        const testId = 'test-file-provider-' + Date.now();
        const setResult = provider.setKey(testId, testKey);
        expect(setResult).toBe(true);
        const retrieved = provider.getKey(testId);
        expect(retrieved).not.toBeNull();
        expect(retrieved.equals(testKey)).toBe(true);
        // Cleanup
        provider.deleteKey(testId);
    });
    it('FileKeyProvider returns null for missing key', () => {
        const provider = new key_provider_file_1.FileKeyProvider();
        if (!provider.isAvailable())
            return;
        const result = provider.getKey('nonexistent-key-' + Date.now());
        expect(result).toBeNull();
    });
    it('FileKeyProvider delete removes key', () => {
        const provider = new key_provider_file_1.FileKeyProvider();
        if (!provider.isAvailable())
            return;
        const testId = 'test-delete-' + Date.now();
        provider.setKey(testId, Buffer.alloc(32, 0xcc));
        expect(provider.getKey(testId)).not.toBeNull();
        const deleted = provider.deleteKey(testId);
        expect(deleted).toBe(true);
        expect(provider.getKey(testId)).toBeNull();
    });
});
describe('Key Migration', () => {
    it('migrateKey returns a result', () => {
        const result = (0, key_migration_1.migrateKey)(process.cwd());
        expect(result).toBeDefined();
        expect(result.provider).toBeDefined();
        expect(result.message).toBeDefined();
    });
    it('getMigrationStatus returns status', () => {
        const status = (0, key_migration_1.getMigrationStatus)();
        expect(typeof status.newProviderHas).toBe('boolean');
        expect(typeof status.oldGlobalExists).toBe('boolean');
        expect(typeof status.needsMigration).toBe('boolean');
    });
});
//# sourceMappingURL=key-provider.test.js.map