"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); const child_process_1 = require("child_process"); const checksumService_1 = require("../../src/services/checksumService"); const archiveReader_1 = require("../../src/services/archiveReader"); const crypto_1 = require("crypto"); function hasBinary(bin) { try { (0, child_process_1.execSync)(`which ${bin}`, { stdio: 'ignore' }); return true; } catch (e) { return false; } } const wantIntegration = process.env.INTEGRATION === '1'; const canCreate = hasBinary('7z') || hasBinary('zip'); if (!wantIntegration) { vitest_1.test.skip('archiveReader integration tests require INTEGRATION=1', () => { }); } else if (!canCreate) { vitest_1.test.skip('archiveReader integration tests skipped: no archive creation tool (7z or zip) available', () => { }); } else { (0, vitest_1.test)('reads entry from zip using system tools', async () => { const tmpDir = await fs_1.promises.mkdtemp(path_1.default.join(process.cwd(), 'tmp-arc-')); const inner = path_1.default.join(tmpDir, 'game.rom'); const content = 'QUASAR-INTEGRATION-TEST'; await fs_1.promises.writeFile(inner, content); const archivePath = path_1.default.join(tmpDir, 'simple.zip'); // create zip using available tool if (hasBinary('7z')) { (0, child_process_1.execSync)(`7z a -tzip ${JSON.stringify(archivePath)} ${JSON.stringify(inner)}`, { stdio: 'ignore', }); } else { (0, child_process_1.execSync)(`zip -j ${JSON.stringify(archivePath)} ${JSON.stringify(inner)}`, { stdio: 'ignore', }); } const stream = await (0, archiveReader_1.streamArchiveEntry)(archivePath, path_1.default.basename(inner)); (0, vitest_1.expect)(stream).not.toBeNull(); const hashes = await (0, checksumService_1.computeHashesFromStream)(stream); const expectedMd5 = (0, crypto_1.createHash)('md5').update(content).digest('hex'); (0, vitest_1.expect)(hashes.md5).toBe(expectedMd5); await fs_1.promises.rm(tmpDir, { recursive: true, force: true }); }); }