import { execFileSync } from "node:child_process"; import { existsSync, mkdtempSync, readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { dirname, join, resolve } from "node:path"; import { tmpdir } from "node:os"; import { describe, expect, it } from "vitest"; const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), ".."); const RELEASE_SCRIPTS = ["scripts/release.ts", "scripts/release-firefox.ts"]; function readReleaseScript(path: string): string { return readFileSync(join(ROOT, path), "utf8"); } function signCommand(script: string): string { const start = script.indexOf('"npx web-ext sign"'); const end = script.indexOf('].join(" ")', start); return script.slice(start, end); } describe("Firefox release source submission", () => { it("passes the generated source archive to web-ext sign in both entry points", () => { for (const path of RELEASE_SCRIPTS) { const command = signCommand(readReleaseScript(path)); expect(command).toContain('"--upload-source-code",'); expect(command).toContain("sourceZip"); expect(command.match(/--upload-source-code/g)).toHaveLength(1); } }); it("builds an archive containing the reviewed crypto source and Noise build script", () => { const archive = join(mkdtempSync(join(tmpdir(), "peach-source-test-")), "source.zip"); execFileSync( "zip", [ "-q", "-r", archive, "src", "scripts", "public", "crypto-core", "manifest.json", "manifest.firefox.json", "package.json", "bun.lock", "tsconfig.json", "vite.config.ts", "--exclude", "node_modules/*", "--exclude", "dist-*/*", "--exclude", "crypto-core/target/*", "--exclude", "crypto-core/generated/*", "--exclude", "*.zip", "--exclude", ".DS_Store", "--exclude", "__MACOSX/*", ], { cwd: ROOT }, ); const contents = execFileSync("unzip", ["-Z1", archive], { encoding: "utf8" }).split("\n"); expect(contents).toEqual( expect.arrayContaining([ "crypto-core/Cargo.toml", "crypto-core/Cargo.lock", "crypto-core/src/lib.rs", "scripts/build-noise-core.mjs", ]), ); for (const path of RELEASE_SCRIPTS) { const script = readReleaseScript(path); expect(script).toContain('"crypto-core",'); expect(existsSync(join(ROOT, "crypto-core/Cargo.toml"))).toBe(true); expect(existsSync(join(ROOT, "crypto-core/Cargo.lock"))).toBe(true); expect(existsSync(join(ROOT, "crypto-core/src/lib.rs"))).toBe(true); expect(existsSync(join(ROOT, "scripts/build-noise-core.mjs"))).toBe(true); } }); });