CodeNomad/scripts/prepare-node-runtime.test.cjs
Pascal André 7869e609b3
feat(opencode): enforce stable runtime support and add managed setup
Require stable OpenCode >=2.0.11 <3.0.0 from authenticated daemon metadata before functional clients and plugin provisioning. Keep bounded contract recognition, connection-generation fencing and native ownership checks while retiring old request, response and event conversions.

Unify missing and outdated runtime recovery with Preferences. Install exact stable releases through bundled Node/npm into a verified versioned user prefix, preserve custom and WSL selections, and separate installation from explicit shared-service restart through the native-parent starter. Fence stale setup responses, retain pending folder opening and never replay prompts.

Certify isolated 2.0.3-to-2.0.11 history migration with executable hashes, untouched seed storage, paginated messages, forks, compaction checkpoints, location moves and pending inbox data. Add minimum/latest cross-platform migration and installation gates, packaged npm closure checks, real Solid recovery regressions and supported-contract authority tests.

Validated server/UI types, focused unit and reducer suites, browser captures, actual packaging-prepared Node 24.20.0 installation without system Node, and native location, automation and pruning fixtures. Document packaged-desktop, WSL, broader historical-state and remote-CI evidence as remaining release gates.
2026-09-20 16:09:36 +02:00

63 lines
3 KiB
JavaScript

const assert = require("node:assert/strict")
const fs = require("node:fs")
const path = require("node:path")
const test = require("node:test")
const yaml = require("yaml")
const os = require("node:os")
const { MANAGED_NODE_VERSION } = require("./prepare-node-runtime.cjs")
const root = path.resolve(__dirname, "..")
const read = (file) => fs.readFileSync(path.join(root, file), "utf8")
test("pins the bundled runtime to the exact Node 24 LTS used by CI", () => {
const version = read(".node-version").trim()
assert.match(version, /^24\.\d+\.\d+$/)
assert.equal(MANAGED_NODE_VERSION, `v${version}`)
})
test("all Node setup steps use the checked-out runtime pin", () => {
const workflows = fs.readdirSync(path.join(root, ".github/workflows"))
.filter((file) => /\.ya?ml$/.test(file))
let checked = 0
for (const file of workflows) {
const workflow = yaml.parse(read(`.github/workflows/${file}`))
for (const job of Object.values(workflow.jobs ?? {})) {
const steps = job.steps ?? []
for (const [index, step] of steps.entries()) {
if (!step.uses?.startsWith("actions/setup-node@")) continue
assert.equal(step.with?.["node-version-file"], ".node-version", file)
assert.equal(step.with?.["node-version"], undefined, file)
assert.ok(steps.slice(0, index).some((earlier) => earlier.uses?.startsWith("actions/checkout@")), file)
checked++
}
}
}
assert.ok(checked > 0)
})
test("both macOS bundles require the OS supported by Node 24", () => {
const electron = JSON.parse(read("packages/electron-app/package.json"))
const tauri = JSON.parse(read("packages/tauri-app/src-tauri/tauri.conf.json"))
assert.equal(electron.build.mac.minimumSystemVersion, "13.5")
assert.equal(tauri.bundle.macOS.minimumSystemVersion, "13.5")
})
test("both desktop resource layouts retain the complete npm runtime and licenses", () => {
const { pruneForRuntime } = require("./prepare-node-runtime.cjs")
const fixture = fs.mkdtempSync(path.join(os.tmpdir(), "codenomad-node-packaging-"))
try {
for (const binary of ["node.exe", "bin/node"]) {
const source = path.join(fixture, binary === "node.exe" ? "windows" : "posix")
const destination = `${source}-out`
const npm = binary === "node.exe" ? "node_modules/npm" : "lib/node_modules/npm"
for (const file of [binary, "LICENSE", `${npm}/bin/npm-cli.js`, `${npm}/node_modules/fixture/index.js`, `${npm}/LICENSE`]) {
fs.mkdirSync(path.dirname(path.join(source, file)), { recursive: true })
fs.writeFileSync(path.join(source, file), file)
}
pruneForRuntime(source, destination, binary)
assert.equal(fs.readFileSync(path.join(destination, `${npm}/node_modules/fixture/index.js`), "utf8"), `${npm}/node_modules/fixture/index.js`)
assert.ok(fs.existsSync(path.join(destination, "LICENSE")))
assert.ok(fs.existsSync(path.join(destination, `${npm}/bin/npm-cli.js`)))
}
} finally { fs.rmSync(fixture, { recursive: true, force: true }) }
})