diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 99c8ebc91..d88aaa4d9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,6 +16,10 @@ jobs: node: [22, 24, 26] os: # https://github.com/actions/runner-images#available-images + # darwin arm64 prebuild stays on macos-26. Building on xcode-27 + # (macOS 27) would use the macOS 27 SDK and can raise the minimum + # OS the published binary requires. A macos-26 binary still runs + # on macOS 27. tests.yml covers xcode-27. - name: darwin host: macos-26 #arm64 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3ed6f4f0e..40421c34c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -69,7 +69,8 @@ jobs: strategy: matrix: node-version: [22, 24, 26] - runner: ["macos-26", "macos-15-intel"] + # xcode-27 is the macOS 27 arm64 image. There is no macos-27 label. + runner: ["macos-26", "xcode-27", "macos-15-intel"] runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v5 diff --git a/CLAUDE.md b/CLAUDE.md index 907ada858..0e6a11f54 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -101,7 +101,7 @@ Tests are located in: ## CI/CD GitHub Actions workflows: -- **tests.yml**: Runs tests on Ubuntu 22.04 and macOS-26 across Node 22, 24, and 26 +- **tests.yml**: Runs tests on Ubuntu 22.04, macOS 26, macOS 27 (`xcode-27`), and the macOS 15 Intel runner across Node 22, 24, and 26 - **publish.yml**: Handles package publishing ## Architecture diff --git a/generate/templates/templates/binding.gyp b/generate/templates/templates/binding.gyp index 88799b0fd..fe33fda7c 100644 --- a/generate/templates/templates/binding.gyp +++ b/generate/templates/templates/binding.gyp @@ -9,7 +9,7 @@ "electron_openssl_static%": " { + if (settled) { + return; + } switch (message) { case "numbersMatch": testOk = true; @@ -129,17 +140,17 @@ if (Worker) { worker.terminate(); break; case "failure": - assert.fail(); + finish(new Error("worker reported failure")); break; } }); - worker.on("error", () => assert.fail()); + worker.on("error", () => finish(new Error("worker error"))); worker.on("exit", (code) => { if (code === 1 && testOk === true) { - done(); + finish(); } else { - assert.fail(); + finish(new Error("worker exited with code " + code)); } }); }); @@ -188,6 +199,14 @@ if (Worker) { return; } let testOk; + let settled = false; + function finish(err) { + if (settled) { + return; + } + settled = true; + done(err); + } const workerPath = local("../utils/worker_context_aware_checkout.js"); const worker = new Worker(workerPath, { workerData: { @@ -196,6 +215,9 @@ if (Worker) { } }); worker.on("message", (message) => { + if (settled) { + return; + } switch (message) { case "numbersMatch": testOk = true; @@ -206,17 +228,17 @@ if (Worker) { worker.terminate(); break; case "failure": - assert.fail(); + finish(new Error("worker reported failure")); break; } }); - worker.on("error", () => assert.fail()); + worker.on("error", () => finish(new Error("worker error"))); worker.on("exit", (code) => { if (code === 1 && testOk === true) { - done(); + finish(); } else { - assert.fail(); + finish(new Error("worker exited with code " + code)); } }); }); diff --git a/test/utils/garbage_collect.js b/test/utils/garbage_collect.js index a288b99c8..8b005b34d 100644 --- a/test/utils/garbage_collect.js +++ b/test/utils/garbage_collect.js @@ -1,11 +1,17 @@ -// aggressively collects garbage until we fail to improve terminatingIterations -// times. -function garbageCollect() { +// Aggressively collects garbage until we fail to improve terminatingIterations +// times. maxIterations caps a worker-thread caller: one global.gc() that keeps +// freeing a little memory would otherwise loop until the suite timeout. +function garbageCollect(maxIterations) { var terminatingIterations = 3; var usedBeforeGC = Number.MAX_VALUE; var nondecreasingIterations = 0; + var iterations = 0; for ( ; ; ) { global.gc(); + iterations++; + if (maxIterations && iterations >= maxIterations) { + break; + } var usedAfterGC = process.memoryUsage().heapUsed; if (usedAfterGC >= usedBeforeGC) { nondecreasingIterations++; diff --git a/test/utils/worker_context_aware.js b/test/utils/worker_context_aware.js index b7784fdae..36e0ac951 100644 --- a/test/utils/worker_context_aware.js +++ b/test/utils/worker_context_aware.js @@ -22,6 +22,7 @@ const opts = { }; let repository; +let reported = false; const oid = "fce88902e66c72b5b93e75bdb5ae717038b221f6"; return NodeGit.Clone(url, clonePath, opts) @@ -35,10 +36,16 @@ return NodeGit.Clone(url, clonePath, opts) var history = commit.history(); history.on("commit", function(commit) { + if (reported) { + return; + } // Number of commits is known to be higher than 200 if (++historyCount == 200) { - // Tracked objects must work too when the Garbage Collector is triggered - garbageCollect(); + reported = true; + // Tracked objects must work too when the Garbage Collector is triggered. + // Cap the collections: an unbounded loop blocked this worker for the + // whole test timeout on Node 24 built with Xcode 27. + garbageCollect(5); // Count total of objects left after being created/destroyed const freeingCount = @@ -58,10 +65,14 @@ return NodeGit.Clone(url, clonePath, opts) } } }); - + history.on("end", function(commits) { - // Test should not get this far - parentPort.postMessage("failure"); + // The walk continues past the 200th commit. That end is not a failure + // once the count has already been reported; posting it made the parent + // assert after the test had moved on. + if (!reported) { + parentPort.postMessage("failure"); + } }); history.on("error", function(err) { diff --git a/test/utils/worker_context_aware_checkout.js b/test/utils/worker_context_aware_checkout.js index 6562915a4..b136f6823 100644 --- a/test/utils/worker_context_aware_checkout.js +++ b/test/utils/worker_context_aware_checkout.js @@ -44,8 +44,9 @@ return NodeGit.Clone(url, clonePath, cloneOpts) return loopingCheckoutHead(clonePath, repository, 10); }).then(function() { assert.strictEqual(applyCallbackResult, 0); - // Tracked objects must work too when the Garbage Collector is triggered - garbageCollect(); + // Tracked objects must work too when the Garbage Collector is triggered. + // Cap the collections so a worker cannot loop in gc until the suite timeout. + garbageCollect(5); // Count total of objects left after being created/destroyed const freeingCount = diff --git a/utils/macOSDeploymentTarget.js b/utils/macOSDeploymentTarget.js new file mode 100644 index 000000000..cc8fc553d --- /dev/null +++ b/utils/macOSDeploymentTarget.js @@ -0,0 +1,41 @@ +const { execFileSync } = require("child_process"); + +const DEFAULT_TARGET = "10.11"; +// Xcode 27's libc++ no longer supports a deployment target below macOS 11. +const XCODE_27_TARGET = "11.0"; + +function deploymentTargetForSdk(version) { + if (!version) { + return DEFAULT_TARGET; + } + const major = Number.parseInt(String(version).split(".")[0], 10); + if (Number.isFinite(major) && major >= 27) { + return XCODE_27_TARGET; + } + return DEFAULT_TARGET; +} + +function sdkVersion() { + if (process.platform !== "darwin") { + return null; + } + try { + return execFileSync("xcrun", ["--sdk", "macosx", "--show-sdk-version"], { + encoding: "utf8", + stdio: ["ignore", "pipe", "ignore"] + }).trim(); + } + catch (error) { + return null; + } +} + +if (require.main === module) { + process.stdout.write(deploymentTargetForSdk(sdkVersion())); +} + +module.exports = { + DEFAULT_TARGET, + XCODE_27_TARGET, + deploymentTargetForSdk +}; diff --git a/utils/macOSDeploymentTarget.test.js b/utils/macOSDeploymentTarget.test.js new file mode 100644 index 000000000..51ceb61ab --- /dev/null +++ b/utils/macOSDeploymentTarget.test.js @@ -0,0 +1,19 @@ +const assert = require("assert"); +const test = require("node:test"); +const { + DEFAULT_TARGET, + XCODE_27_TARGET, + deploymentTargetForSdk +} = require("./macOSDeploymentTarget"); + +test("keeps the historical deployment target on older SDKs", function() { + assert.strictEqual(deploymentTargetForSdk(null), DEFAULT_TARGET); + assert.strictEqual(deploymentTargetForSdk("26.6"), DEFAULT_TARGET); + assert.strictEqual(deploymentTargetForSdk("11.0"), DEFAULT_TARGET); +}); + +test("raises the deployment target when the SDK is macOS 27 or newer", function() { + assert.strictEqual(deploymentTargetForSdk("27.0"), XCODE_27_TARGET); + assert.strictEqual(deploymentTargetForSdk("27.1"), XCODE_27_TARGET); + assert.strictEqual(XCODE_27_TARGET, "11.0"); +});