Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion generate/templates/templates/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"electron_openssl_static%": "<!(node -p \"process.platform !== 'linux' || process.env.NODEGIT_OPENSSL_STATIC_LINK === '1' ? 1 : 0\")",
"cxx_version%": "<!(node ./utils/defaultCxxStandard.js \"<(target)\" \"<(node_root_dir)\")",
"has_cxxflags%": "<!(node -p \"process.env.CXXFLAGS ? 1 : 0\")",
"macOS_deployment_target": "10.11",
"macOS_deployment_target": "<!(node ./utils/macOSDeploymentTarget.js)",
# https://github.com/nodejs/node-gyp/issues/2673
'openssl_fips': '',
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"installDebug": "BUILD_DEBUG=true npm install",
"lint": "jshint lib test/tests test/utils lifecycleScripts",
"mergecov": "lcov-result-merger 'test/**/*.info' 'test/coverage/merged.lcov' && ./lcov-1.10/bin/genhtml test/coverage/merged.lcov --output-directory test/coverage/report",
"mocha": "node --test utils/defaultCxxStandard.test.js && mocha --expose-gc test/runner test/tests --timeout 15000",
"mocha": "node --test utils/defaultCxxStandard.test.js utils/macOSDeploymentTarget.test.js && mocha --expose-gc test/runner test/tests --timeout 15000",
"mochaDebug": "mocha --expose-gc --inspect-brk test/runner test/tests --timeout 15000",
"postinstall": "node lifecycleScripts/postinstall",
"rebuild": "node generate && node-gyp configure build",
Expand Down
38 changes: 30 additions & 8 deletions test/tests/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,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.js");
const worker = new Worker(workerPath, {
workerData: {
Expand All @@ -119,6 +127,9 @@ if (Worker) {
}
});
worker.on("message", (message) => {
if (settled) {
return;
}
switch (message) {
case "numbersMatch":
testOk = true;
Expand All @@ -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));
}
});
});
Expand Down Expand Up @@ -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: {
Expand All @@ -196,6 +215,9 @@ if (Worker) {
}
});
worker.on("message", (message) => {
if (settled) {
return;
}
switch (message) {
case "numbersMatch":
testOk = true;
Expand All @@ -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));
}
});
});
Expand Down
12 changes: 9 additions & 3 deletions test/utils/garbage_collect.js
Original file line number Diff line number Diff line change
@@ -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++;
Expand Down
21 changes: 16 additions & 5 deletions test/utils/worker_context_aware.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const opts = {
};

let repository;
let reported = false;
const oid = "fce88902e66c72b5b93e75bdb5ae717038b221f6";

return NodeGit.Clone(url, clonePath, opts)
Expand All @@ -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 =
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions test/utils/worker_context_aware_checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
41 changes: 41 additions & 0 deletions utils/macOSDeploymentTarget.js
Original file line number Diff line number Diff line change
@@ -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
};
19 changes: 19 additions & 0 deletions utils/macOSDeploymentTarget.test.js
Original file line number Diff line number Diff line change
@@ -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");
});
Loading