"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const windows_adapter_1 = require("../../../src/adapters/windows-adapter");
const errors_1 = require("../../../src/types/errors");
describe('WindowsAdapter 内部行为', () => {
    it('在 WMI 数据缺失 Size 时应限制磁盘占用不为负值', async () => {
        const adapter = new windows_adapter_1.WindowsAdapter();
        const internal = adapter;
        let callCount = 0;
        internal.executePowerShell = async () => {
            callCount += 1;
            if (callCount === 1) {
                throw new errors_1.MonitorError('psdrive failed', errors_1.ErrorCode.COMMAND_FAILED, 'win32');
            }
            return [
                {
                    DeviceID: 'C:',
                    FileSystem: 'NTFS',
                    FreeSpace: '1024'
                }
            ];
        };
        const disks = await adapter.getDiskInfo();
        (0, chai_1.expect)(disks).to.have.lengthOf(1);
        (0, chai_1.expect)(disks[0].mountPoint).to.equal('C:');
        (0, chai_1.expect)(disks[0].used).to.equal(0);
        (0, chai_1.expect)(disks[0].available).to.equal(1024);
        (0, chai_1.expect)(disks[0].usagePercentage).to.equal(0);
    });
    it('在网络统计命令失败时应抛出 MonitorError', async () => {
        const adapter = new windows_adapter_1.WindowsAdapter();
        const internal = adapter;
        internal.executePowerShell = async () => {
            throw new errors_1.MonitorError('stats failed', errors_1.ErrorCode.COMMAND_FAILED, 'win32');
        };
        try {
            await adapter.getNetworkStats();
            chai_1.expect.fail('应该抛出 MonitorError');
        }
        catch (error) {
            (0, chai_1.expect)(error).to.be.instanceOf(errors_1.MonitorError);
        }
    });
});
describe('WindowsAdapter — Deno 兼容性降级', () => {
    describe('T007: getCPUInfo() — PowerShell 失败时降级到 os.cpus()', () => {
        it('应返回基于 os.cpus()/os.loadavg() 的有效非零 CPU 数据，而非抛出异常', async () => {
            const adapter = new windows_adapter_1.WindowsAdapter();
            const internal = adapter;
            // stub executePowerShell 使其抛出异常（模拟 Deno 中 PowerShell 不可用）
            internal.executePowerShell = async () => {
                throw new errors_1.MonitorError('PowerShell 不可用', errors_1.ErrorCode.COMMAND_FAILED, 'win32');
            };
            // 不应抛出，应返回基于 os.cpus() 的数据
            const result = await adapter.getCPUInfo();
            (0, chai_1.expect)(result).to.be.an('object');
            (0, chai_1.expect)(result.cores).to.be.a('number').and.to.be.greaterThan(0);
            (0, chai_1.expect)(result.model).to.be.a('string').and.to.have.length.greaterThan(0);
            (0, chai_1.expect)(result.threads).to.be.a('number').and.to.be.greaterThan(0);
        });
    });
});
describe('WindowsAdapter — Deno 兼容性降级 (T021: US2)', () => {
    let adapter;
    let internal;
    beforeEach(() => {
        adapter = new windows_adapter_1.WindowsAdapter();
        internal = adapter;
        // stub executePowerShell 使所有 PowerShell 命令失败
        internal.executePowerShell = async () => {
            throw new errors_1.MonitorError('PowerShell 不可用', errors_1.ErrorCode.COMMAND_FAILED, 'win32');
        };
    });
    it('T021: getMemoryInfo() 应返回基于 os.totalmem()/os.freemem() 的有效内存数据', async () => {
        const result = await adapter.getMemoryInfo();
        (0, chai_1.expect)(result).to.be.an('object');
        (0, chai_1.expect)(result.total).to.be.a('number').and.to.be.greaterThan(0);
        (0, chai_1.expect)(result.available).to.be.a('number').and.to.be.greaterThan(0);
        (0, chai_1.expect)(result.used).to.be.a('number').and.to.be.at.least(0);
    });
    it('T021: getNetworkStats() 在命令失败时应抛出 MonitorError(COMMAND_FAILED)，不返回静默空数组', async () => {
        try {
            await adapter.getNetworkStats();
            chai_1.expect.fail('应该抛出 MonitorError');
        }
        catch (error) {
            (0, chai_1.expect)(error).to.be.instanceOf(errors_1.MonitorError);
            (0, chai_1.expect)(error.code).to.equal(errors_1.ErrorCode.COMMAND_FAILED);
        }
    });
    it('T021: getDiskInfo() 在命令失败时应抛出 MonitorError，不静默返回数据', async () => {
        try {
            await adapter.getDiskInfo();
            chai_1.expect.fail('应该抛出 MonitorError');
        }
        catch (error) {
            (0, chai_1.expect)(error).to.be.instanceOf(errors_1.MonitorError);
        }
    });
    it('T021: getProcessList() 在命令失败时应抛出 MonitorError(COMMAND_FAILED)，不静默返回数据', async () => {
        try {
            await adapter.getProcessList();
            chai_1.expect.fail('应该抛出 MonitorError');
        }
        catch (error) {
            (0, chai_1.expect)(error).to.be.instanceOf(errors_1.MonitorError);
        }
    });
});
//# sourceMappingURL=windows-adapter.test.js.map