diff --git a/.agents/skills/release-preparation/SKILL.md b/.agents/skills/release-preparation/SKILL.md index 3c1c6d3..9c0977a 100644 --- a/.agents/skills/release-preparation/SKILL.md +++ b/.agents/skills/release-preparation/SKILL.md @@ -5,8 +5,8 @@ description: Preparing a duroxide-node npm release PR without publishing. Use wh # Preparing a duroxide-node Release -Prepare the public release changes for review. Publishing is performed separately -by a Microsoft maintainer through the internal release pipeline. +Prepare the public release changes for review. Registry publishing is performed +separately by a Microsoft maintainer through the internal release pipeline. ## 1. Confirm the Release @@ -19,6 +19,10 @@ Before editing, identify: Follow Semantic Versioning and the policy in [RELEASE_POLICY.md](../../../RELEASE_POLICY.md). +A runtime-floor increase is a breaking change requiring at least the next minor +version on 0.x. Maintenance releases are outside the current release flow and +require a separate approved plan. + ## 2. Synchronize npm Versions Set the target version in: @@ -30,6 +34,15 @@ Set the target version in: All six package versions and all five optional dependency versions must match. Do not change the `Cargo.toml` package version as part of an npm-only release. +Also synchronize `engines.node` in the root and all five platform manifests, +including the root entry in `package-lock.json`; the manifests define the +supported floor. +After packing, run `node ci/smoke/check-engines.js ` to check +all six distributable manifests, not just the source files. A future intentional +floor increase must update this check, the loader hint in `lib/duroxide.js`, +its tests in `__tests__/native_loader.test.js`, and the runtime documentation. +This check covers GitHub-built tarballs, not internal-pipeline artifacts. + ## 3. Finalize the Changelog In `CHANGELOG.md`: @@ -51,11 +64,44 @@ Create a pull request targeting `main`. GitHub Actions validates the full SDK test suite, cross-platform builds, and local-package smoke tests on the pull request. +Confirm the `Build & Smoke` workflow succeeds before merging. ## 5. Maintainer Handoff -After the pull request is merged, release preparation is complete. +After the pull request is merged, the release-preparation PR work is complete. +Every new SDK version tag requires notes-only GitHub release notes. +Adopting this policy does not change existing tags or releases. -Do not run `npm publish`, create a GitHub Release, or add publishing credentials +Do not run `npm publish` or add publishing credentials, publishing workflows, or internal pipeline configuration. A Microsoft maintainer runs the internal -release pipeline. +release pipeline; npm publishing remains exclusive to that pipeline. + +### Tag Authorization + +Tag creation is a separate action requiring explicit developer authorization +for the version and exact release commit SHA, not the current tip of `main`. +Confirm the approved commit contains the merged release changes and has a +successful `Build & Smoke` run. Check local and remote tags first. If the tag +already exists, verify its commit matches the approved SHA and do not recreate it. +If absent and authorized, create it with `git tag "$TAG" "$RELEASE_SHA"` and push +only that tag with `git push origin "refs/tags/$TAG"`. Never move or delete tags. + +### GitHub Notes + +1. The notes step never creates a tag. Fetch the existing remote tag without + force; compare `git rev-parse "$TAG^{commit}"` with the approved release SHA + and confirm `Build & Smoke` passed for that commit. Stop on a missing tag or + mismatched SHA. Inspect existing release state, body, and assets; stop on + inconsistencies; reuse a matching approved draft instead of creating a + duplicate, and do not alter unrelated existing releases. +2. Use the tagged changelog and upgrade notes. Ask for timing if unspecified: + notes may precede or follow npm. An explicit request to publish notes is + approval; tag authorization alone is not. Without publication approval, + prepare only a safe draft. +3. Use `gh release create "$TAG" --verify-tag --notes-file "$NOTES_FILE"`, + adding `--draft` for preparation, `--latest=false` for older/non-highest + stable versions, and `--prerelease` for prereleases. Check these flags when + publishing an approved draft too. Do not upload package assets. +4. If notes precede npm, include "npm publication pending". Update those notes + when publication is confirmed, or state that the version was not published + if abandoned. Never move or delete the tag. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fbc0aae..f44eff4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -116,6 +116,8 @@ jobs: done - name: Pack main package run: npm pack --pack-destination "$GITHUB_WORKSPACE/tarballs" + - name: Check packed runtime requirements + run: node ci/smoke/check-engines.js tarballs - name: List tarballs run: ls -lh tarballs/ - name: Upload tarballs @@ -156,6 +158,7 @@ jobs: - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: ${{ matrix.node }} + check-latest: true - name: Download tarballs uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index f8ceeb3..e847586 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- The next minor release (0.4.0) requires Node.js 22 or newer for `duroxide` +- Starting with 0.4.0, Node.js 22 or newer is required for `duroxide` and its native platform packages. Upgrade from Node.js 18 or 20 before installing 0.4.0. The requirement for 0.3.0 is unchanged. +### Fixed + +- Explain possible runtime and install-time Node.js version causes when a + published native platform package is missing, while preserving the original + error as the cause and retaining its `code` and `requireStack`. + ## [0.3.0] - 2026-11-30 ### Changed diff --git a/RELEASE_POLICY.md b/RELEASE_POLICY.md index a2e1a23..268b290 100644 --- a/RELEASE_POLICY.md +++ b/RELEASE_POLICY.md @@ -1,15 +1,16 @@ # Release Policy `duroxide` and its platform packages are published to npm by Microsoft's -internal open-source release infrastructure. Publishing credentials and release -execution remain outside this repository. +internal open-source release infrastructure. Registry publishing credentials +and execution remain outside this repository. ## Contributor Workflow Contributors can prepare a release through a pull request: 1. Keep the root package version, every `npm/npm/*/package.json` version, and - all platform `optionalDependencies` aligned. + all platform `optionalDependencies` aligned. Keep `engines.node` aligned + across all six manifests and the lockfile root, and check the packed tarballs. 2. Update `CHANGELOG.md` and relevant documentation. 3. Open a pull request for review. GitHub Actions runs the build, tests, and package smoke checks. @@ -17,11 +18,36 @@ Contributors can prepare a release through a pull request: After the release change is merged, a Microsoft maintainer runs the internal release pipeline to build and publish the packages to npm. +## Supported Runtimes + +The supported Node.js floor is defined by the package manifests' `engines.node`. +Increasing it is a breaking change requiring at least the next minor SDK +version on 0.x. Maintenance releases are not supported by the current release +flow and require a separate approved plan. + ## Publishing Boundary - Do not run `npm publish` for the Microsoft release. -- Do not create a GitHub Release manually. +- Do not upload package assets or add publishing workflows. - Do not request or store Microsoft publishing credentials in this repository. +## GitHub Releases + +Every new SDK version tag must have a notes-only GitHub Release using that tag's +changelog and upgrade notes. Verify the immutable tag matches the approved +release commit; creating tags requires separate explicit authorization. +The notes step never creates tags or duplicates releases. Adopting this policy +does not change existing tags or releases; never move, recreate, or delete tags. + +The developer's request controls whether notes precede or follow npm publication. +Ask if timing is unspecified. An explicit request to publish notes is approval; +tag authorization alone is not. A safe draft may be prepared without publication +approval. If notes precede npm, mark publication pending and update the status +when confirmed or abandoned. Stop on inconsistent release state. + +GitHub Releases are independent of npm publication and do not publish packages. +See the [release-preparation skill](.agents/skills/release-preparation/SKILL.md) +for verification and publication steps. + For release questions, open a GitHub issue without including credentials or internal pipeline configuration. diff --git a/__tests__/native_loader.test.js b/__tests__/native_loader.test.js new file mode 100644 index 0000000..2a6b0b2 --- /dev/null +++ b/__tests__/native_loader.test.js @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +const { describe, it } = require('node:test'); +const assert = require('node:assert/strict'); +const { spawnSync } = require('node:child_process'); +const { copyFileSync, mkdtempSync, mkdirSync, readFileSync, rmSync } = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const vm = require('node:vm'); + +const root = path.join(__dirname, '..'); +const source = readFileSync(path.join(root, 'lib', 'duroxide.js'), 'utf8'); +const manifest = require('../package.json'); + +describe('native loader diagnostics', () => { + it('still exports the SDK when native bindings load successfully', () => { + const context = { + module: { exports: {} }, + require(name) { + assert.equal(name, '../index.js'); + return {}; + }, + }; + vm.runInNewContext(source, context); + for (const name of ['SqliteProvider', 'PostgresProvider', 'Client', 'Runtime']) { + assert.equal(typeof context.module.exports[name], 'function'); + } + }); + + it('explains a missing optional package through the real generated loader', (t) => { + const directory = mkdtempSync(path.join(os.tmpdir(), 'duroxide-loader-')); + t.after(() => rmSync(directory, { recursive: true, force: true })); + mkdirSync(path.join(directory, 'lib')); + copyFileSync(path.join(root, 'index.js'), path.join(directory, 'index.js')); + copyFileSync(path.join(root, 'package.json'), path.join(directory, 'package.json')); + copyFileSync(path.join(root, 'lib', 'duroxide.js'), path.join(directory, 'lib', 'duroxide.js')); + const script = ` + const assert = require('node:assert/strict'); + assert.throws(() => require('./lib/duroxide'), (error) => { + assert.match(error.message, /Cannot find module 'duroxide-/); + assert.match(error.message, /running on Node.js older than 22/); + assert.match(error.message, /installing with Node.js older than 22/); + assert.match(error.message, /install-time Node.js version/); + assert.match(error.message, /Other causes include omitted optional dependencies/); + assert.match(error.message, /reinstall with optional dependencies enabled/); + assert.equal(error.cause.code, 'MODULE_NOT_FOUND'); + assert.equal(error.code, 'MODULE_NOT_FOUND'); + assert.equal(error.requireStack, error.cause.requireStack); + assert.ok(error.message.startsWith(error.cause.message)); + assert.match(error.cause.stack, /index.js/); + assert.ok(error.cause.requireStack.some((file) => file.endsWith('index.js'))); + return true; + }); + `; + const child = spawnSync(process.execPath, ['-e', script], { + cwd: directory, encoding: 'utf8', env: { ...process.env, NODE_PATH: '' }, timeout: 10000, + }); + assert.equal(child.status, 0, child.stderr || String(child.error)); + }); + + it('keeps the original error and its existing cause', () => { + const cause = new Error('underlying failure'); + const original = new Error("Cannot find module 'duroxide-linux-x64-gnu'", { cause }); + original.code = 'MODULE_NOT_FOUND'; + original.requireStack = ['index.js', 'lib/duroxide.js']; + assert.throws(() => vm.runInNewContext(source, { + require(name) { + if (name === '../package.json') return manifest; + throw original; + }, + }), (error) => { + assert.equal(error.cause, original); + assert.equal(error.cause.cause, cause); + assert.equal(error.code, original.code); + assert.equal(error.requireStack, original.requireStack); + return true; + }); + }); + + for (const packageName of ['duroxide-linux-x64-musl', 'duroxide-win32-arm64', 'duroxide-freebsd-x64']) { + it(`does not give reinstall or Node-version advice for unpublished ${packageName}`, () => { + const original = new Error(`Cannot find module '${packageName}'`); + original.code = 'MODULE_NOT_FOUND'; + assert.throws(() => vm.runInNewContext(source, { + require(name) { + if (name === '../package.json') return manifest; + throw original; + }, + }), (error) => { + assert.equal(error, original); + assert.doesNotMatch(error.message, /Node.js|reinstall/); + return true; + }); + }); + } + + it('preserves the native error when the package manifest cannot be read', () => { + const original = new Error("Cannot find module 'duroxide-linux-x64-gnu'"); + original.code = 'MODULE_NOT_FOUND'; + assert.throws(() => vm.runInNewContext(source, { + require(name) { + if (name === '../package.json') throw new SyntaxError('Invalid package manifest'); + throw original; + }, + }), (error) => error === original); + }); + + it('preserves the native error when the manifest has no optional dependencies', () => { + const original = new Error("Cannot find module 'duroxide-linux-x64-gnu'"); + original.code = 'MODULE_NOT_FOUND'; + assert.throws(() => vm.runInNewContext(source, { + require(name) { + if (name === '../package.json') return {}; + throw original; + }, + }), (error) => error === original); + }); + + for (const [code, message] of [ + ['MODULE_NOT_FOUND', "Cannot find module 'unrelated-dependency'"], + ['MODULE_NOT_FOUND', "Cannot find module '../index.js'"], + ['ERR_DLOPEN_FAILED', 'Native library could not be opened'], + [undefined, 'Unsupported architecture'], + ]) { + it(`does not replace unrelated load errors: ${message}`, () => { + const original = new Error(message); + original.code = code; + assert.throws(() => vm.runInNewContext(source, { + require() { throw original; }, + }), (error) => error === original); + }); + } +}); diff --git a/__tests__/package_engines.test.js b/__tests__/package_engines.test.js new file mode 100644 index 0000000..d516e1b --- /dev/null +++ b/__tests__/package_engines.test.js @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +const { describe, it } = require('node:test'); +const assert = require('node:assert/strict'); +const { execFileSync, spawnSync } = require('node:child_process'); +const { mkdtempSync, mkdirSync, writeFileSync, rmSync } = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const { checkPackedEngines } = require('../ci/smoke/check-engines'); +const { name, optionalDependencies } = require('../package.json'); + +function packedManifests(t, change = () => {}) { + const root = mkdtempSync(path.join(os.tmpdir(), 'duroxide-engines-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + const directory = path.join(root, 'tarballs'); + const packageDirectory = path.join(root, 'package'); + mkdirSync(directory); + mkdirSync(packageDirectory); + const manifests = [name, ...Object.keys(optionalDependencies)] + .map((name) => ({ name, version: '0.4.0', engines: { node: '>=22' } })); + change(manifests); + for (const [index, manifest] of manifests.entries()) { + writeFileSync(path.join(packageDirectory, 'package.json'), JSON.stringify(manifest)); + execFileSync('tar', [ + '-czf', path.join('tarballs', `${index}.tgz`), 'package/package.json', + ], { cwd: root }); + } + return directory; +} + +describe('packed runtime requirements', () => { + it('the CLI succeeds on valid tarballs and fails when all six have the wrong floor', (t) => { + const checker = path.join(__dirname, '..', 'ci', 'smoke', 'check-engines.js'); + for (const floor of ['>=22', '>=18']) { + const directory = packedManifests(t, (manifests) => { + for (const manifest of manifests) manifest.engines.node = floor; + }); + const child = spawnSync(process.execPath, [checker, path.basename(directory)], { + cwd: path.dirname(directory), encoding: 'utf8', timeout: 10000, + }); + assert.ifError(child.error); + if (floor === '>=22') { + assert.equal(child.status, 0, child.stderr); + assert.match(child.stdout, /All six packed engines.node values match >=22/); + } else { + assert.notEqual(child.status, 0); + assert.match(child.stderr, /must declare engines.node >=22/); + } + } + }); + + it('accepts all six tarballs with engines.node >=22', (t) => { + checkPackedEngines(packedManifests(t)); + }); + + for (const floor of ['>=18', '>=20', '>=24']) { + it(`rejects all six agreeing on the wrong floor ${floor}`, (t) => { + const directory = packedManifests(t, (manifests) => { + for (const manifest of manifests) manifest.engines.node = floor; + }); + assert.throws(() => checkPackedEngines(directory), /must declare engines.node >=22/); + }); + } + + it('rejects all six missing engines', (t) => { + const directory = packedManifests(t, (manifests) => { + for (const manifest of manifests) delete manifest.engines; + }); + assert.throws(() => checkPackedEngines(directory), /must declare engines.node >=22/); + }); + + for (const name of Object.keys(optionalDependencies)) { + it(`rejects a missing floor in ${name}`, (t) => { + const directory = packedManifests(t, (manifests) => { + manifests.find((manifest) => manifest.name === name).engines = {}; + }); + assert.throws(() => checkPackedEngines(directory), /engines.node must match/); + }); + } + + it('rejects a platform floor that differs from the main package', (t) => { + const directory = packedManifests(t, (manifests) => { + manifests[1].engines.node = '>=18'; + }); + assert.throws(() => checkPackedEngines(directory), /engines.node must match/); + }); + + it('rejects a missing platform tarball', (t) => { + const directory = packedManifests(t, (manifests) => manifests.pop()); + assert.throws(() => checkPackedEngines(directory), /all five platform tarballs/); + }); + + it('rejects a duplicate platform in place of another', (t) => { + const directory = packedManifests(t, (manifests) => { + manifests[1].name = manifests[2].name; + }); + assert.throws(() => checkPackedEngines(directory), /all five platform tarballs/); + }); +}); diff --git a/ci/smoke/README.md b/ci/smoke/README.md index 2116cbf..69e1f1e 100644 --- a/ci/smoke/README.md +++ b/ci/smoke/README.md @@ -6,6 +6,19 @@ napi-rs platform subpackage, runs a minimal SQLite-backed orchestration. CI packs the tarballs on Node.js 24 and tests those same tarballs on Node.js 22, 24, and 26 for each supported OS and architecture. +Floating smoke versions use `check-latest: true` to pick up current security +patches rather than an older runner-cached version. + +Before uploading tarballs, `node ci/smoke/check-engines.js tarballs` checks the +packed `package.json` for the main package and all five platform packages built +by GitHub CI. It does not verify packages built by the internal release pipeline. +All six `engines.node` values must match and must explicitly be `>=22`; agreement +on a missing or outdated floor is rejected. Run the focused packaging and +loader tests without a native build or database: + +```bash +node --test __tests__/package_engines.test.js __tests__/native_loader.test.js +``` Motivated by [microsoft/duroxide#13](https://github.com/microsoft/duroxide/issues/13): the Windows platform subpackage was renamed from `duroxide-win32-x64-msvc` to @@ -18,6 +31,7 @@ back to the local `.node` binary when run from the repo. | File | Purpose | |--------------------------|-------------------------------------------------| | `smoke.mjs` | Hello-world orchestration using `SqliteProvider`. | +| `check-engines.js` | Assert the Node.js floor in all six packed manifests. | | `run-local.sh` / `.ps1` | Install from local tarballs (pre-publish). | | `run-registry.sh` / `.ps1` | Install from npm registry (post-publish). | diff --git a/ci/smoke/check-engines.js b/ci/smoke/check-engines.js new file mode 100644 index 0000000..d2cfd10 --- /dev/null +++ b/ci/smoke/check-engines.js @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +const assert = require('node:assert/strict'); +const { execFileSync } = require('node:child_process'); +const { readdirSync } = require('node:fs'); + +const packageNames = [ + 'duroxide', + 'duroxide-darwin-arm64', + 'duroxide-darwin-x64', + 'duroxide-linux-arm64-gnu', + 'duroxide-linux-x64-gnu', + 'duroxide-windows-x64', +]; + +function checkPackedEngines(directory) { + const manifests = readdirSync(directory) + .filter((name) => name.endsWith('.tgz')) + .map((name) => JSON.parse(execFileSync( + 'tar', ['-xOf', name, 'package/package.json'], + { cwd: directory, encoding: 'utf8' }, + ))); + + assert.deepEqual( + manifests.map((manifest) => manifest.name).sort(), + packageNames, + 'Expected exactly the main package and all five platform tarballs', + ); + const main = manifests.find((manifest) => manifest.name === 'duroxide'); + assert.equal(main.engines?.node, '>=22', 'duroxide must declare engines.node >=22'); + for (const manifest of manifests) { + assert.equal( + manifest.engines?.node, main.engines.node, + `${manifest.name} engines.node must match duroxide (>=22)`, + ); + } +} + +if (require.main === module) { + assert.equal(process.argv.length, 3, 'Usage: node ci/smoke/check-engines.js '); + checkPackedEngines(process.argv[2]); + console.log('All six packed engines.node values match >=22'); +} + +module.exports = { checkPackedEngines }; diff --git a/docs/user-guide.md b/docs/user-guide.md index a04f51a..1e2b350 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -4,6 +4,11 @@ This guide covers how to build workflows with duroxide-node. For architecture de ## Installation +SDK 0.4.0 and later require Node.js 22 or newer. +SDK 0.3.0 requires Node.js 18 or newer. +GitHub package assets ended with 0.2.4; new GitHub Releases are notes-only. +Install packages from npm. + ```bash npm install duroxide ``` diff --git a/lib/duroxide.js b/lib/duroxide.js index 8d00044..1c04835 100644 --- a/lib/duroxide.js +++ b/lib/duroxide.js @@ -9,7 +9,38 @@ */ // Load native bindings from the auto-generated napi-rs loader -const { JsSqliteProvider, JsPostgresProvider, JsClient, JsRuntime, activityTraceLog, orchestrationTraceLog, activityIsCancelled, activityGetClient, activityTag, orchestrationSetCustomStatus, orchestrationResetCustomStatus, orchestrationGetCustomStatus, orchestrationSetValue, orchestrationGetValue, orchestrationClearValue, orchestrationClearAllValues, orchestrationGetKvAllValues, orchestrationGetKvAllKeys, orchestrationGetKvLength, orchestrationPruneKvValues, initTracing } = require('../index.js'); +let nativeBinding; +try { + nativeBinding = require('../index.js'); +} catch (error) { + const missingPackage = error?.code === 'MODULE_NOT_FOUND' && + /^Cannot find module ['"](duroxide-[^'"]+)['"]/.exec(error.message); + if (missingPackage) { + let manifest; + try { + manifest = require('../package.json'); + } catch { + throw error; + } + if (!manifest?.optionalDependencies || + !Object.hasOwn(manifest.optionalDependencies, missingPackage[1])) { + throw error; + } + const wrapped = new Error( + `${error.message}\nThe native platform package is missing. Possible causes include ` + + 'running on Node.js older than 22 or installing with Node.js older than 22: npm may skip ' + + 'optional packages based on the install-time Node.js version. Other causes include omitted ' + + 'optional dependencies or an incomplete install. Use Node.js 22+ for both installation and ' + + 'execution, then reinstall with optional dependencies enabled.', + { cause: error }, + ); + wrapped.code = error.code; + wrapped.requireStack = error.requireStack; + throw wrapped; + } + throw error; +} +const { JsSqliteProvider, JsPostgresProvider, JsClient, JsRuntime, activityTraceLog, orchestrationTraceLog, activityIsCancelled, activityGetClient, activityTag, orchestrationSetCustomStatus, orchestrationResetCustomStatus, orchestrationGetCustomStatus, orchestrationSetValue, orchestrationGetValue, orchestrationClearValue, orchestrationClearAllValues, orchestrationGetKvAllValues, orchestrationGetKvAllKeys, orchestrationGetKvLength, orchestrationPruneKvValues, initTracing } = nativeBinding; // ─── Generator Driver ────────────────────────────────────────────