SurfSense/surfsense_local/electron/scripts/opencode/sign-mac.test.mjs
DESKTOP-RTLN3BA\$punk ba5162f1ce fix(release): keep opencode's own macOS signature
The pinned opencode-darwin-arm64 arrives Developer ID signed by Anomaly
Innovations, with the hardened runtime, a secure timestamp and the five
entitlements Bun asks for. osx-sign force-signed it with the app's inherited
entitlements, which lack disable-executable-page-protection, and the release's
--version smoke barely runs Bun's JIT. mac.signIgnore now leaves opencode's
signature in place; rg arrives only ad-hoc signed and is still signed with the
app.

packaging.md also had Windows wrong: opencode.exe arrives Authenticode-signed
by its vendor and rg.exe unsigned, and a tag's build replaces both with
SurfSense's signature, so a dry run does not run an unsigned opencode.
2026-10-07 13:33:12 -07:00

33 lines
1.3 KiB
JavaScript

import assert from "node:assert/strict"
import { readFileSync } from "node:fs"
import test from "node:test"
/** `mac.signIgnore` in electron-builder.yml, as the regexes electron-builder makes of it. */
function signIgnore() {
const yml = readFileSync(new URL("../../electron-builder.yml", import.meta.url), "utf8").replace(/\r\n/g, "\n")
const mac = yml.match(/^mac:\n((?:[ \t]+.*\n|\n)*)/m)?.[1] ?? ""
const list = mac.match(/^ signIgnore:\n((?: - .*\n)*)/m)?.[1] ?? ""
return list
.split("\n")
.filter(Boolean)
.map((line) => new RegExp(line.replace(/^\s*-\s*"?/, "").replace(/"\s*$/, "")))
}
// osx-sign tests each file's absolute path against the filter.
const contents = "/runner/release/mac-arm64/SurfSense.app/Contents"
const skipped = (path) => signIgnore().some((pattern) => pattern.test(path))
test("opencode keeps its vendor's signature, whose entitlements are the ones Bun needs", () => {
assert.ok(skipped(`${contents}/Resources/opencode/opencode`))
})
test("everything else is still signed with the app, rg included, which arrives ad-hoc signed", () => {
for (const path of [
`${contents}/Resources/opencode/rg`,
`${contents}/MacOS/SurfSense`,
`${contents}/Resources/llamacpp/llama-server`,
`${contents}/Resources/backend/api/opencode`,
]) {
assert.ok(!skipped(path), path)
}
})