Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
The so101 CLI runs under Node: `node bin/so101 --help` and `ports` no longer reach bun:sqlite #573
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/570-the-so101-cli-runs-under-node-node-bin-s → main 1 commit fork
2 files
changed +42
−1
Software/so101/src/cli-node.test.ts added +41
| @@ -0,0 +1,41 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { spawnSync } from "node:child_process"; | |
| 3 | import { readFileSync } from "node:fs"; | |
| 4 | ||
| 5 | // The README promises a fresh clone runs under Node 22.6+ (types stripped at load). A Bun-only import reached from the CLI | |
| 6 | // (bun:sqlite, say) crashes it on a laptop while every Bun test passes. | |
| 7 | const version = spawnSync("node", ["--version"], { encoding: "utf8" }); | |
| 8 | const [major = 0, minor = 0] = (version.stdout ?? "").replace(/^v/, "").split(".").map(Number); | |
| 9 | const strips = version.status === 0 && (major > 22 || (major === 22 && minor >= 6)); | |
| 10 | const cli = new URL("../bin/so101", import.meta.url).pathname; | |
| 11 | ||
| 12 | function so101(...args: string[]) { | |
| 13 | return spawnSync("node", ["--experimental-strip-types", "--no-warnings", cli, ...args], { encoding: "utf8", timeout: 30_000 }); | |
| 14 | } | |
| 15 | ||
| 16 | test.skipIf(!strips)("--help and ports run under Node", () => { | |
| 17 | const help = so101("--help"); | |
| 18 | expect(help.stderr).toBe(""); | |
| 19 | expect(help.stdout).toContain("usage: so101"); | |
| 20 | expect(help.status).toBe(0); | |
| 21 | expect(so101("ports").status).toBe(0); | |
| 22 | }); | |
| 23 | ||
| 24 | test("the CLI's static imports never reach a bun: module", () => { | |
| 25 | const seen = new Set<string>(); | |
| 26 | const offenders: string[] = []; | |
| 27 | const walk = (url: URL) => { | |
| 28 | if (seen.has(url.href)) return; | |
| 29 | seen.add(url.href); | |
| 30 | const source = readFileSync(url, "utf8"); | |
| 31 | // static only: `import … from "x"` and `export … from "x"`, not dynamic import() | |
| 32 | for (const match of source.matchAll(/^\s*(?:import|export)\b[^;]*?\bfrom\s+["']([^"']+)["']|^\s*import\s+["']([^"']+)["']/gm)) { | |
| 33 | const spec = match[1] ?? match[2] ?? ""; | |
| 34 | if (spec.startsWith("bun:") || spec === "bun") offenders.push(`${url.pathname} imports ${spec}`); | |
| 35 | else if (spec.startsWith(".")) walk(new URL(spec, url)); | |
| 36 | } | |
| 37 | }; | |
| 38 | walk(new URL("./cli.ts", import.meta.url)); | |
| 39 | expect(seen.size).toBeGreaterThan(3); | |
| 40 | expect(offenders).toEqual([]); | |
| 41 | }); |
Software/so101/src/cli.ts +1 −1
| @@ -6,7 +6,6 @@ import { describeError, hex } from "./protocol.ts"; | ||
| 6 | 6 | import { MAX_FRAME_STEP, MotionError, moveToPose, name as jointName, playTrajectory, recordTrajectory, sleep } from "./motion.ts"; |
| 7 | 7 | import { streamLeader } from "./leader.ts"; |
| 8 | 8 | import { assertPoseName, parsePoseFile, serializePoseFile, type PoseFile } from "./poses.ts"; |
| 9 | import { startServer } from "./server.ts"; | |
| 10 | 9 | import { durationSeconds, largestStep, parseTrajectory, serializeTrajectory } from "./trajectory.ts"; |
| 11 | 10 | import { |
| 12 | 11 | BAUD_RATES, |
| @@ -498,6 +497,7 @@ const COMMANDS: Record<string, Command> = { | ||
| 498 | 497 | const [host, portText] = (values.listen ?? "0.0.0.0:8101").split(":"); |
| 499 | 498 | const port = bounded(integer(portText ?? "8101", "--listen port"), 1, 65535, "--listen port"); |
| 500 | 499 | return withBus(values, async (bus) => { |
| 500 | const { startServer } = await import("./server.ts"); // lazily: it reaches bun:sqlite, which Node lacks | |
| 501 | 501 | const server = await startServer(bus, { host, port, posesFile: values.file ?? "poses.json", modelDir: values.model, gainSyncMs: 2000 }); |
| 502 | 502 | console.log(`serving ${bus.path} on http://${host}:${server.port} — open it in a browser; the API is listed in src/server.ts`); |
| 503 | 503 | console.log("ctrl-c to stop"); |
new above
offline