import { describe, it, expect, beforeAll } from "vitest"; import { execFileSync } from "node:child_process"; import { existsSync, statSync, rmSync } from "node:fs"; import { join, dirname } from "node:path"; import { fileURLToPath } from "node:url"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const repoRoot = join(__dirname, ".."); const SUPPORTED_HOST = "x86_64-pc-windows-msvc"; function detectHostTriple() { try { const output = execFileSync("rustc", ["-vV"], { encoding: "utf8" }); const line = output.split("\n").find((l) => l.startsWith("host:")); return line ? line.replace("host:", "").trim() : null; } catch { return null; } } describe("setup-sidecar", () => { const hostTriple = detectHostTriple(); beforeAll(() => { if (!hostTriple) { console.warn("rustc não disponível; pulando teste de sidecar"); } }); it("baixa o binário oficial e o coloca em src-tauri/binaries com o target triple", async () => { if (!hostTriple) return; if (hostTriple !== SUPPORTED_HOST) { console.log(`host triple ${hostTriple} fora da matriz de testes; pulando`); return; } const binaryPath = join(repoRoot, "src-tauri", "binaries", `sherpa-onnx-offline-${hostTriple}.exe`); if (existsSync(binaryPath)) { rmSync(binaryPath, { force: true }); } execFileSync("node", [join(repoRoot, "scripts", "setup-sidecar.mjs")], { stdio: "pipe", env: { ...process.env, SHERPA_ONNX_VERSION: "v1.12.23" }, }); expect(existsSync(binaryPath)).toBe(true); expect(statSync(binaryPath).size).toBeGreaterThan(1024 * 1024); }, 180_000); });