The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
style: reformat stage-modules script and tests
Steven Enamakel715d4e6c3e4c
diff --git a/scripts/__tests__/stage-modules.test.mjs b/scripts/__tests__/stage-modules.test.mjsindex 68c9e9b12d..bc6dd6eee6 100644--- a/scripts/__tests__/stage-modules.test.mjs+++ b/scripts/__tests__/stage-modules.test.mjs@@ -80,46 +80,64 @@ test("the default host key is the oldest published build for each platform", ()assert.throws(() => defaultHostKey("freebsd", "x64"), /no bundled modules/);});-test("Windows extraction rejects an archive entry escaping its destination", {- skip: process.platform !== "win32",-}, () => {- const root = mkdtempSync(join(tmpdir(), "openhuman-zip-boundary-"));- const destination = join(root, "modules");- mkdirSync(destination);- const archive = join(root, "escape.zip");- const name = Buffer.from("../escape.txt");- const local = Buffer.alloc(30);- local.writeUInt32LE(0x04034b50, 0);- local.writeUInt16LE(20, 4);- local.writeUInt16LE(name.length, 26);- const central = Buffer.alloc(46);- central.writeUInt32LE(0x02014b50, 0);- central.writeUInt16LE(20, 4);- central.writeUInt16LE(20, 6);- central.writeUInt16LE(name.length, 28);- const end = Buffer.alloc(22);- end.writeUInt32LE(0x06054b50, 0);- end.writeUInt16LE(1, 8);- end.writeUInt16LE(1, 10);- end.writeUInt32LE(central.length + name.length, 12);- end.writeUInt32LE(local.length + name.length, 16);- writeFileSync(archive, Buffer.concat([local, name, central, name, end]));+test(+ "Windows extraction rejects an archive entry escaping its destination",+ {+ skip: process.platform !== "win32",+ },+ () => {+ const root = mkdtempSync(join(tmpdir(), "openhuman-zip-boundary-"));+ const destination = join(root, "modules");+ mkdirSync(destination);+ const archive = join(root, "escape.zip");+ const name = Buffer.from("../escape.txt");+ const local = Buffer.alloc(30);+ local.writeUInt32LE(0x04034b50, 0);+ local.writeUInt16LE(20, 4);+ local.writeUInt16LE(name.length, 26);+ const central = Buffer.alloc(46);+ central.writeUInt32LE(0x02014b50, 0);+ central.writeUInt16LE(20, 4);+ central.writeUInt16LE(20, 6);+ central.writeUInt16LE(name.length, 28);+ const end = Buffer.alloc(22);+ end.writeUInt32LE(0x06054b50, 0);+ end.writeUInt16LE(1, 8);+ end.writeUInt16LE(1, 10);+ end.writeUInt32LE(central.length + name.length, 12);+ end.writeUInt32LE(local.length + name.length, 16);+ writeFileSync(archive, Buffer.concat([local, name, central, name, end]));- assert.throws(- () => extractWindowsZip(archive, destination),- (error) => /outside/i.test(error.stderr?.toString() ?? ""),- );- assert.throws(() => readFileSync(join(root, "escape.txt")), { code: "ENOENT" });-});+ assert.throws(+ () => extractWindowsZip(archive, destination),+ (error) => /outside/i.test(error.stderr?.toString() ?? ""),+ );+ assert.throws(() => readFileSync(join(root, "escape.txt")), {+ code: "ENOENT",+ });+ },+);test("host keys follow the Rust target triple, not the runner", () => {assert.equal(hostKeyForTarget("aarch64-apple-darwin"), "macos-15-arm64");assert.equal(hostKeyForTarget("x86_64-apple-darwin"), "macos-15-x86_64");- assert.equal(hostKeyForTarget("x86_64-unknown-linux-gnu"), "ubuntu-22.04-x86_64");- assert.equal(hostKeyForTarget("aarch64-unknown-linux-gnu"), "ubuntu-22.04-arm64");- assert.equal(hostKeyForTarget("x86_64-pc-windows-msvc"), "windows-2022-x86_64");+ assert.equal(+ hostKeyForTarget("x86_64-unknown-linux-gnu"),+ "ubuntu-22.04-x86_64",+ );+ assert.equal(+ hostKeyForTarget("aarch64-unknown-linux-gnu"),+ "ubuntu-22.04-arm64",+ );+ assert.equal(+ hostKeyForTarget("x86_64-pc-windows-msvc"),+ "windows-2022-x86_64",+ );assert.equal(hostKeyForTarget("aarch64-pc-windows-msvc"), "windows-11-arm64");- assert.throws(() => hostKeyForTarget("wasm32-unknown-unknown"), /no bundled modules/);+ assert.throws(+ () => hostKeyForTarget("wasm32-unknown-unknown"),+ /no bundled modules/,+ );});test("only macOS bundles replace the archive with its digest marker", () => {@@ -140,7 +158,10 @@ test("a macOS entry keeps only the archive's verified digest, in tinybus's markeassert.equal(existsSync(archive), false, "the archive must not ship");// tinybus reads `<archive>.sha256`, trims it and compares it to the pin.assert.equal(readFileSync(`${archive}.sha256`, "utf8"), `${sha}\n`);- assert.equal(readFileSync(join(dir, "libdemo.dylib"), "utf8"), "library bytes");+ assert.equal(+ readFileSync(join(dir, "libdemo.dylib"), "utf8"),+ "library bytes",+ );});async function withServer(handler, run) {@@ -158,10 +179,13 @@ test("download keeps the archive bytes and refuses a content-encoded body", asynconst dir = mkdtempSync(join(tmpdir(), "openhuman-download-"));const out = join(dir, "a.bin");const raw = Buffer.from("raw archive bytes");- await withServer((req, res) => res.end(raw), async (url) => {- await download(url, out, 5000);- assert.deepEqual(readFileSync(out), raw);- });+ await withServer(+ (req, res) => res.end(raw),+ async (url) => {+ await download(url, out, 5000);+ assert.deepEqual(readFileSync(out), raw);+ },+ );await withServer((req, res) => {res.setHeader("content-encoding", "gzip");@@ -180,7 +204,10 @@ test("a stalled download times out instead of hanging", async () => {res.write("partial");},async (url) => {- await assert.rejects(download(url, join(dir, "a.bin"), 200), /download of/);+ await assert.rejects(+ download(url, join(dir, "a.bin"), 200),+ /download of/,+ );},);});@@ -190,7 +217,9 @@ for (const hostKey of ["macos-15-arm64", "ubuntu-22.04-x86_64"]) {const root = mkdtempSync(join(tmpdir(), "openhuman-stage-"));const source = join(root, "src");mkdirSync(source);- const library = hostKey.startsWith("macos-") ? "libdemo.dylib" : "libdemo.so";+ const library = hostKey.startsWith("macos-")+ ? "libdemo.dylib"+ : "libdemo.so";writeFileSync(join(source, library), "library bytes");const archiveName = `demo-1.0.0-${hostKey}.tar.gz`;const built = join(root, archiveName);@@ -199,13 +228,25 @@ for (const hostKey of ["macos-15-arm64", "ubuntu-22.04-x86_64"]) {const sha256 = createHash("sha256").update(bytes).digest("hex");const output = join(root, "out");- await withServer((req, res) => res.end(bytes), async (url) => {- await stageModules({- hostKey,- output,- assets: [{ id: "demo", version: "1.0.0", hostKey, archive: archiveName, url, sha256 }],- });- });+ await withServer(+ (req, res) => res.end(bytes),+ async (url) => {+ await stageModules({+ hostKey,+ output,+ assets: [+ {+ id: "demo",+ version: "1.0.0",+ hostKey,+ archive: archiveName,+ url,+ sha256,+ },+ ],+ });+ },+ );const dir = join(output, "demo", "1.0.0", hostKey);assert.equal(readFileSync(join(dir, library), "utf8"), "library bytes");@@ -213,8 +254,15 @@ for (const hostKey of ["macos-15-arm64", "ubuntu-22.04-x86_64"]) {assert.deepEqual(readFileSync(join(dir, archiveName)), bytes);assert.equal(existsSync(join(dir, `${archiveName}.sha256`)), false);} else {- assert.equal(existsSync(join(dir, archiveName)), false, "the archive must not ship");- assert.equal(readFileSync(join(dir, `${archiveName}.sha256`), "utf8"), `${sha256}\n`);+ assert.equal(+ existsSync(join(dir, archiveName)),+ false,+ "the archive must not ship",+ );+ assert.equal(+ readFileSync(join(dir, `${archiveName}.sha256`), "utf8"),+ `${sha256}\n`,+ );}});}@@ -234,63 +282,86 @@ function modesUnder(root) {// account can write ("module directory is writable by another user"). The// staged tree ships inside the AppImage/deb as-is, so it must not carry the// build host's umask or the release tarball's mode bits.-test("staged modules carry no group or other write bits, whatever the umask and archive modes", {- skip: process.platform === "win32",-}, async () => {- const hostKey = "ubuntu-22.04-x86_64";- const root = mkdtempSync(join(tmpdir(), "openhuman-stage-modes-"));- const source = join(root, "src");- mkdirSync(join(source, "lib"), { recursive: true });- const library = "lib/libdemo.so";- writeFileSync(join(source, library), "library bytes");- writeFileSync(join(source, "README"), "notes");- chmodSync(join(source, "lib"), 0o777);- chmodSync(join(source, library), 0o777);- chmodSync(join(source, "README"), 0o666);- const archiveName = `demo-1.0.0-${hostKey}.tar.gz`;- const built = join(root, archiveName);- execFileSync("tar", ["-czf", built, "-C", source, "lib", "README"]);- const bytes = readFileSync(built);- const sha256 = createHash("sha256").update(bytes).digest("hex");- const output = join(root, "out");+test(+ "staged modules carry no group or other write bits, whatever the umask and archive modes",+ {+ skip: process.platform === "win32",+ },+ async () => {+ const hostKey = "ubuntu-22.04-x86_64";+ const root = mkdtempSync(join(tmpdir(), "openhuman-stage-modes-"));+ const source = join(root, "src");+ mkdirSync(join(source, "lib"), { recursive: true });+ const library = "lib/libdemo.so";+ writeFileSync(join(source, library), "library bytes");+ writeFileSync(join(source, "README"), "notes");+ chmodSync(join(source, "lib"), 0o777);+ chmodSync(join(source, library), 0o777);+ chmodSync(join(source, "README"), 0o666);+ const archiveName = `demo-1.0.0-${hostKey}.tar.gz`;+ const built = join(root, archiveName);+ execFileSync("tar", ["-czf", built, "-C", source, "lib", "README"]);+ const bytes = readFileSync(built);+ const sha256 = createHash("sha256").update(bytes).digest("hex");+ const output = join(root, "out");- // Ubuntu's user-private-group default.- const previousUmask = process.umask(0o002);- try {- await withServer((req, res) => res.end(bytes), async (url) => {- await stageModules({- hostKey,- output,- assets: [{ id: "demo", version: "1.0.0", hostKey, archive: archiveName, url, sha256 }],- });- });- } finally {- process.umask(previousUmask);- }+ // Ubuntu's user-private-group default.+ const previousUmask = process.umask(0o002);+ try {+ await withServer(+ (req, res) => res.end(bytes),+ async (url) => {+ await stageModules({+ hostKey,+ output,+ assets: [+ {+ id: "demo",+ version: "1.0.0",+ hostKey,+ archive: archiveName,+ url,+ sha256,+ },+ ],+ });+ },+ );+ } finally {+ process.umask(previousUmask);+ }- const entries = [- { path: output, mode: lstatSync(output).mode & 0o7777, dir: true },- ...modesUnder(output),- ];- assert.ok(entries.some((e) => e.path.endsWith("libdemo.so")), "the library was staged");- for (const { path, mode, dir } of entries) {- assert.equal(mode, dir ? 0o755 : 0o644, `${path} is ${mode.toString(8)}`);- }-});+ const entries = [+ { path: output, mode: lstatSync(output).mode & 0o7777, dir: true },+ ...modesUnder(output),+ ];+ assert.ok(+ entries.some((e) => e.path.endsWith("libdemo.so")),+ "the library was staged",+ );+ for (const { path, mode, dir } of entries) {+ assert.equal(mode, dir ? 0o755 : 0o644, `${path} is ${mode.toString(8)}`);+ }+ },+);-test("normalising staged permissions never follows a symlink out of the tree", {- skip: process.platform === "win32",-}, () => {- const root = mkdtempSync(join(tmpdir(), "openhuman-stage-symlink-"));- const outside = join(root, "outside");- writeFileSync(outside, "not staged");- chmodSync(outside, 0o600);- const staged = join(root, "staged");- mkdirSync(staged);- symlinkSync(outside, join(staged, "link"));+test(+ "normalising staged permissions never follows a symlink out of the tree",+ {+ skip: process.platform === "win32",+ },+ () => {+ const root = mkdtempSync(join(tmpdir(), "openhuman-stage-symlink-"));+ const outside = join(root, "outside");+ writeFileSync(outside, "not staged");+ chmodSync(outside, 0o600);+ const staged = join(root, "staged");+ mkdirSync(staged);+ symlinkSync(outside, join(staged, "link"));- normalizeStagedPermissions(staged);+ normalizeStagedPermissions(staged);- assert.equal(lstatSync(outside).mode & 0o7777, 0o600);- assert.equal(lstatSync(staged).mode & 0o7777, 0o755);-});+ assert.equal(lstatSync(outside).mode & 0o7777, 0o600);+ assert.equal(lstatSync(staged).mode & 0o7777, 0o755);+ },+);diff --git a/scripts/release/stage-modules.mjs b/scripts/release/stage-modules.mjsindex d4fc2f70ee..c4ba637ff0 100644--- a/scripts/release/stage-modules.mjs+++ b/scripts/release/stage-modules.mjs@@ -41,7 +41,10 @@ const OUTPUT = join(ROOT, "crates/openhuman-app/bundled-modules");const LIBRARY_EXTENSIONS = [".dll", ".so", ".dylib"];/** The registry host key to bundle for a Node `platform`/`arch` pair. */-export function defaultHostKey(platform = process.platform, arch = process.arch) {+export function defaultHostKey(+ platform = process.platform,+ arch = process.arch,+) {const archKey = { x64: "x86_64", arm64: "arm64" }[arch];if (!archKey) throw new Error(`no bundled modules for architecture ${arch}`);switch (platform) {@@ -93,7 +96,8 @@ export function bundledAssets(source, hostKey) {const ids = names.map((name) => {const record = records.get(name);if (!record) throw new Error(`missing module record ${name}`);- if (!urls.has(record.id)) throw new Error(`missing release URL for ${record.id}`);+ if (!urls.has(record.id))+ throw new Error(`missing release URL for ${record.id}`);return record.id;});// A module that publishes nothing for this OS is not bundled there;@@ -107,8 +111,16 @@ export function bundledAssets(source, hostKey) {const assets = resolveTestModuleAssets(source, hostKey, wanted);return assets.map((asset) => {const record = [...records.values()].find((r) => r.id === asset.id);- for (const component of [record.id, record.version, hostKey, asset.archive]) {- if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(component) || component === "..") {+ for (const component of [+ record.id,+ record.version,+ hostKey,+ asset.archive,+ ]) {+ if (+ !/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(component) ||+ component === ".."+ ) {throw new Error(`unsafe registry path component for ${record.id}`);}}@@ -121,7 +133,8 @@ function librariesUnder(dir) {const path = join(dir, entry.name);if (entry.isDirectory()) return librariesUnder(path);const name = entry.name.toLowerCase();- return entry.isFile() && LIBRARY_EXTENSIONS.some((ext) => name.endsWith(ext))+ return entry.isFile() &&+ LIBRARY_EXTENSIONS.some((ext) => name.endsWith(ext))? [path]: [];});@@ -173,7 +186,8 @@ export function normalizeStagedPermissions(root) {const stat = lstatSync(root);if (stat.isDirectory()) {chmodSync(root, 0o755);- for (const name of readdirSync(root)) normalizeStagedPermissions(join(root, name));+ for (const name of readdirSync(root))+ normalizeStagedPermissions(join(root, name));} else if (stat.isFile()) {chmodSync(root, 0o644);}@@ -187,7 +201,11 @@ const DOWNLOAD_TIMEOUT_MS = 120_000;* `Content-Encoding: gzip` body, and the registry pin covers the archive's* own bytes. Each attempt has a deadline that also covers the body.*/-export async function download(url, destination, timeoutMs = DOWNLOAD_TIMEOUT_MS) {+export async function download(+ url,+ destination,+ timeoutMs = DOWNLOAD_TIMEOUT_MS,+) {let lastError;for (let attempt = 1; attempt <= 3; attempt += 1) {try {@@ -223,19 +241,29 @@ export async function stageModules({mkdirSync(dir, { recursive: true });const archive = join(dir, asset.archive);await download(asset.url, archive);- const actual = createHash("sha256").update(readFileSync(archive)).digest("hex");+ const actual = createHash("sha256")+ .update(readFileSync(archive))+ .digest("hex");if (actual !== asset.sha256.toLowerCase()) {- throw new Error(`${asset.id}: downloaded archive does not match the compiled registry pin`);+ throw new Error(+ `${asset.id}: downloaded archive does not match the compiled registry pin`,+ );}extractArchive(archive, dir);if (librariesUnder(dir).length !== 1) {- throw new Error(`${asset.id}: expected exactly one native library in the release archive`);+ throw new Error(+ `${asset.id}: expected exactly one native library in the release archive`,+ );}if (!keepsArchive(asset.hostKey)) replaceArchiveWithMarker(archive, actual);- console.log(`[bundled-modules] staged ${asset.id} ${asset.version} (${asset.hostKey})`);+ console.log(+ `[bundled-modules] staged ${asset.id} ${asset.version} (${asset.hostKey})`,+ );}normalizeStagedPermissions(output);- console.log(`[bundled-modules] staged ${assets.length} verified releases for ${hostKey}`);+ console.log(+ `[bundled-modules] staged ${assets.length} verified releases for ${hostKey}`,+ );return output;}@@ -247,7 +275,9 @@ function option(name) {if (process.argv[1] === fileURLToPath(import.meta.url)) {const target = option("--target");await stageModules({- hostKey: option("--host-key") ?? (target ? hostKeyForTarget(target) : defaultHostKey()),+ hostKey:+ option("--host-key") ??+ (target ? hostKeyForTarget(target) : defaultHostKey()),output: option("--output") ? resolve(option("--output")) : OUTPUT,});}