import { execFile } from "node:child_process"; import { promisify } from "node:util"; import { describe, expect, it } from "vitest"; const execFileAsync = promisify(execFile); const scriptPath = "scripts/generate-native-sync-manifest.mjs"; describe("native sync manifest generator", () => { it("generates a Chrome native messaging host manifest", async () => { const { stdout } = await execFileAsync(process.execPath, [ scriptPath, "--browser", "chrome", "--extension-id", "abcdefghijklmnopabcdefghijklmnop", "--host-path", "/opt/peach/peach-sync-host", ]); expect(JSON.parse(stdout)).toEqual({ name: "com.peachpasswords.sync", description: "Peach Sync native messaging host", path: "/opt/peach/peach-sync-host", type: "stdio", allowed_origins: ["chrome-extension://abcdefghijklmnopabcdefghijklmnop/"], }); }); it("generates a Firefox native messaging host manifest using the Gecko id", async () => { const { stdout } = await execFileAsync(process.execPath, [ scriptPath, "--browser", "firefox", "--host-path", "/opt/peach/peach-sync-host", ]); expect(JSON.parse(stdout)).toEqual({ name: "com.peachpasswords.sync", description: "Peach Sync native messaging host", path: "/opt/peach/peach-sync-host", type: "stdio", allowed_extensions: ["peach@peachpasswords.com"], }); }); it("requires a Chrome extension id", async () => { await expect( execFileAsync(process.execPath, [scriptPath, "--browser", "chrome"], { env: { ...process.env, PEACH_CHROME_EXTENSION_ID: "" }, }) ).rejects.toThrow("--extension-id or PEACH_CHROME_EXTENSION_ID is required for Chrome"); }); });