mirror of
https://github.com/NeuralNomadsAI/CodeNomad.git
synced 2026-11-19 23:12:07 +00:00
Move the server to fastify 5.12.8, @fastify/static 10.1.10, @fastify/reply-from 12.8.1 and @fastify/cors 11.4.1 together, clearing the open fastify, @fastify/static, @fastify/reply-from (including the critical one), undici 5, @fastify/busboy and find-my-way alerts. Silent Fastify 5 default changes are neutralised so behaviour stays as before: shared semicolon router option for both apps and routedPath; over-long params reach the gate/CORS/auth lifecycle; reply-from 12 onResponse stream and byte-exact SideCar/preview query forwarding; explicit CORS methods; Fastify 4's extra proxied methods; bodiless DELETE/OPTIONS in instance, SideCar and remote scopes; plain-copy param logging. The desktop resource test pins the reviewed 5.12.8 production version. Lockfile regenerated with npm 11.19.1 (the CI npm), only the Fastify graph changes. Full server suite, typechecks and Fastify-importing browser fixtures pass locally; twelve ablations each fail their guarding tests; independent review found no remaining findings after one round. Full CI is green on the exact head, including native runtime contracts, Electron/Tauri tests and packaged builds.
131 lines
7.7 KiB
JavaScript
131 lines
7.7 KiB
JavaScript
const assert = require("node:assert/strict")
|
|
const fs = require("node:fs")
|
|
const os = require("node:os")
|
|
const path = require("node:path")
|
|
const test = require("node:test")
|
|
const { spawnSync } = require("node:child_process")
|
|
const { resolveNpmTarget, validateServerProductionLock } = require("./desktop-server-resources.cjs")
|
|
const { resolveEsbuildExecutable } = require("../packages/tauri-app/scripts/prebuild.js")
|
|
const { copyPackagedServerResources } = require("./desktop-server-resources.cjs")
|
|
|
|
test("Electron resource verification requires the pinned npm only while Tauri requires Node beside it", t => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "codenomad-runtime-contract-"))
|
|
t.after(() => fs.rmSync(root, { recursive: true, force: true }))
|
|
const npmVersion = fs.readFileSync(path.join(__dirname, "..", ".npm-version"), "utf8").trim()
|
|
const writeNpm = (directory, version = npmVersion) => {
|
|
fs.mkdirSync(path.join(directory, "bin"), { recursive: true })
|
|
fs.writeFileSync(path.join(directory, "bin/npm-cli.js"), "")
|
|
fs.writeFileSync(path.join(directory, "package.json"), JSON.stringify({ name: "npm", version }))
|
|
}
|
|
for (const [target, binary, npm] of [["win32-x64", "node.exe", "node_modules/npm"], ["linux-x64", "bin/node", "lib/node_modules/npm"]]) {
|
|
const directory = path.join(root, "node", target)
|
|
const verify = (...args) => spawnSync(process.execPath, [path.join(__dirname, "verify-bundled-node.cjs"), ...args, `${root}@${target}`])
|
|
writeNpm(path.join(directory, "npm"))
|
|
assert.equal(verify("--npm-only").status, 0)
|
|
assert.notEqual(verify().status, 0)
|
|
writeNpm(path.join(directory, "npm"), "0.0.1")
|
|
assert.notEqual(verify("--npm-only").status, 0, "a stale npm is refused")
|
|
fs.rmSync(directory, { recursive: true })
|
|
fs.mkdirSync(path.dirname(path.join(directory, binary)), { recursive: true })
|
|
fs.writeFileSync(path.join(directory, binary), "")
|
|
writeNpm(path.join(directory, npm))
|
|
assert.notEqual(verify("--npm-only").status, 0)
|
|
assert.equal(verify().status, 0)
|
|
}
|
|
})
|
|
|
|
test("maps every supported desktop target to npm OS and CPU", () => {
|
|
assert.deepEqual(resolveNpmTarget("darwin-x64"), { target: "darwin-x64", os: "darwin", cpu: "x64" })
|
|
assert.deepEqual(resolveNpmTarget("darwin-arm64"), { target: "darwin-arm64", os: "darwin", cpu: "arm64" })
|
|
assert.deepEqual(resolveNpmTarget("linux-x64"), { target: "linux-x64", os: "linux", cpu: "x64" })
|
|
assert.deepEqual(resolveNpmTarget("linux-arm64"), { target: "linux-arm64", os: "linux", cpu: "arm64" })
|
|
assert.deepEqual(resolveNpmTarget("win32-x64"), { target: "win32-x64", os: "win32", cpu: "x64" })
|
|
assert.deepEqual(resolveNpmTarget("win32-arm64"), { target: "win32-arm64", os: "win32", cpu: "arm64" })
|
|
assert.throws(() => resolveNpmTarget("freebsd-x64"), /Unsupported desktop packaging target/)
|
|
})
|
|
|
|
test("glibc desktop resources omit musl-only msgpackr binaries and retain the native loader", t => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "codenomad-glibc-resources-"))
|
|
t.after(() => fs.rmSync(root, { recursive: true, force: true }))
|
|
const serverRoot = path.join(root, "source")
|
|
for (const name of ["public", "dist", "node_modules"]) fs.mkdirSync(path.join(serverRoot, name), { recursive: true })
|
|
fs.writeFileSync(path.join(serverRoot, "package.json"), "{}")
|
|
for (const cpu of ["x64", "arm64"]) {
|
|
const relative = path.join("node_modules", "@msgpackr-extract", `msgpackr-extract-linux-${cpu}`)
|
|
fs.mkdirSync(path.join(serverRoot, relative), { recursive: true })
|
|
for (const name of ["node.napi.glibc.node", "node.abi115.musl.node", "node.napi.musl.node", "index.js", "package.json"]) {
|
|
fs.writeFileSync(path.join(serverRoot, relative, name), name)
|
|
}
|
|
const serverDest = path.join(root, cpu)
|
|
copyPackagedServerResources({ serverRoot, serverDest, target: `linux-${cpu}` })
|
|
assert.deepEqual(fs.readdirSync(path.join(serverDest, relative)).sort(), ["index.js", "node.napi.glibc.node", "package.json"])
|
|
assert(fs.existsSync(path.join(serverRoot, relative, "node.napi.musl.node")), "source installation is untouched")
|
|
}
|
|
})
|
|
|
|
test("integrity-pins the full server production closure in the root lock", () => {
|
|
const root = path.resolve(__dirname, "..")
|
|
const lock = JSON.parse(fs.readFileSync(path.join(root, "package-lock.json"), "utf8"))
|
|
const closure = validateServerProductionLock(lock)
|
|
|
|
assert.ok(closure.size > 100)
|
|
assert.equal(lock.packages["node_modules/fastify"].version, "5.12.8")
|
|
assert.equal(lock.packages["node_modules/undici"].version, "6.29.1")
|
|
assert.equal(lock.packages["packages/server/node_modules/commander"].version, "12.1.0")
|
|
assert.equal(lock.packages["packages/server/node_modules/fuzzysort"].version, "2.0.4")
|
|
assert.equal(closure.has("node_modules/@opencode/plugin"), false, "the opt-in pruning plugin API is not a server production dependency")
|
|
})
|
|
|
|
test("rejects an unpinned production dependency despite an otherwise valid lock", () => {
|
|
const root = path.resolve(__dirname, "..")
|
|
const lock = JSON.parse(fs.readFileSync(path.join(root, "package-lock.json"), "utf8"))
|
|
delete lock.packages["node_modules/undici"].integrity
|
|
assert.throws(() => validateServerProductionLock(lock), /does not integrity-pin node_modules\/undici/)
|
|
})
|
|
|
|
test("resolves a macOS ARM64 esbuild binary nested under esbuild", (t) => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "codenomad-esbuild-"))
|
|
t.after(() => fs.rmSync(root, { recursive: true, force: true }))
|
|
const esbuildRoot = path.join(root, "node_modules", "esbuild")
|
|
const platformRoot = path.join(esbuildRoot, "node_modules", "@esbuild", "darwin-arm64")
|
|
fs.mkdirSync(path.join(platformRoot, "bin"), { recursive: true })
|
|
fs.writeFileSync(path.join(esbuildRoot, "package.json"), JSON.stringify({ name: "esbuild", version: "0.25.12" }))
|
|
fs.writeFileSync(path.join(platformRoot, "package.json"), JSON.stringify({
|
|
name: "@esbuild/darwin-arm64",
|
|
version: "0.25.12",
|
|
os: ["darwin"],
|
|
cpu: ["arm64"],
|
|
}))
|
|
fs.writeFileSync(path.join(platformRoot, "bin", "esbuild"), "")
|
|
|
|
assert.equal(fs.existsSync(path.join(root, "node_modules", "@esbuild", "darwin-arm64")), false)
|
|
assert.deepEqual(resolveEsbuildExecutable(root, "darwin", "arm64"), {
|
|
executable: path.join(platformRoot, "bin", "esbuild"),
|
|
version: "0.25.12",
|
|
})
|
|
})
|
|
|
|
for (const feature of ["automation", "memory"])
|
|
test(`both desktop resource layouts retain a self-contained ${feature} bundle`, async (t) => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "codenomad-automation-resources-"))
|
|
t.after(() => fs.rmSync(root, { recursive: true, force: true }))
|
|
const serverRoot = path.join(root, "source")
|
|
for (const name of ["public", "node_modules"]) fs.mkdirSync(path.join(serverRoot, name), { recursive: true })
|
|
fs.writeFileSync(path.join(serverRoot, "package.json"), JSON.stringify({ type: "module" }))
|
|
const relative = path.join("dist", "plugins", feature, "plugin.mjs")
|
|
await require("esbuild").build({
|
|
entryPoints: [path.join(__dirname, `../packages/server/src/opencode/${feature}/desktop-plugin.ts`)],
|
|
outfile: path.join(serverRoot, relative), bundle: true, platform: "node", format: "esm", target: "node22",
|
|
})
|
|
for (const host of ["electron", "tauri"]) {
|
|
const serverDest = path.join(root, host, "server")
|
|
copyPackagedServerResources({ serverRoot, serverDest })
|
|
const target = path.join(serverDest, relative)
|
|
assert.deepEqual(fs.readFileSync(target), fs.readFileSync(path.join(serverRoot, relative)))
|
|
const { desktopPlugin } = await import(require("node:url").pathToFileURL(target).href)
|
|
const plugin = desktopPlugin(path.join(root, "absent-presence"))
|
|
assert.equal(plugin.id, `codenomad.${feature}`)
|
|
const cleanup = await plugin.setup({})
|
|
await cleanup()
|
|
}
|
|
})
|