Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

bench/launch-check.ts checks a deployed URL as an anonymous visitor and prints PASS/FAIL per item - against today's main #149

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

smith/arm:smith/145-bench-launch-check-ts-checks-a-deployed → main 3 commits fork 2 threads · 2 unresolved

  • Merged. smith/145-bench-launch-check-ts-checks-a-deployed was merged into main as 8efb73f.

Review

Sign in to review this change.
3 files changed +180 −0
Software/README.md +12
@@ -685,6 +685,18 @@ The vision kit in `Software/vision` works against this server and stream:
685685 `SO101_ARM=http://<pi>:8101 SO101_CAMERA=http://<pi>:8080/stream`, then the
686686 `just vision-*` recipes. See `Software/vision/QUEST.md`.
687687
688 ## Launch check
689
690 `so101/bench/launch-check.ts` checks a deployed page as an anonymous visitor and
691 prints one PASS/FAIL line per item (the page and its security headers, `/status`,
692 `/live` pushing a status, and the refusal of anonymous and forged-identity
693 commands). It exits non-zero on any FAIL and sends nothing that could move the arm.
694
695 ```
696 bun run so101/bench/launch-check.ts https://arm--forge-trevato-apps.open-platform.sh # production
697 bun run so101/bench/launch-check.ts https://arm--<pull number>--forge-trevato-apps.open-platform.sh # a preview
698 ```
699
688700 ## LeRobot flow
689701
690702 Follows the [SO-101 guide](https://huggingface.co/docs/lerobot/so101). The
Software/so101/bench/launch-check.test.ts added +39
@@ -0,0 +1,39 @@
1 import { afterAll, beforeAll, expect, test } from "bun:test";
2 import { mkdtempSync, rmSync } from "node:fs";
3 import { tmpdir } from "node:os";
4 import { join } from "node:path";
5 import { FeetechBus } from "../src/bus.ts";
6 import { FakeBus } from "../src/fake-bus.ts";
7 import { Lobby } from "../src/lobby.ts";
8 import { startRelay, type RunningRelay } from "../src/relay.ts";
9 import { startServer, type RunningServer } from "../src/server.ts";
10 import { runChecks } from "./launch-check.ts";
11
12 let dir = "";
13 let simulation: RunningServer;
14 let relay: RunningRelay;
15
16 beforeAll(async () => {
17 dir = mkdtempSync(join(tmpdir(), "so101-launch-"));
18 const ids = [1, 2, 3, 4, 5, 6];
19 simulation = await startServer(new FeetechBus(new FakeBus(ids)), { host: "127.0.0.1", port: 0, ids, posesFile: join(dir, "poses.json"), modelDir: new URL("../../../Simulation/SO101", import.meta.url).pathname });
20 const lobby = new Lobby({ identityKey: "k".repeat(64), adminFile: join(dir, "admin.json") });
21 relay = await startRelay({ port: 0, simulation: `http://127.0.0.1:${simulation.port}`, lobby });
22 });
23
24 afterAll(async () => {
25 await Promise.race([relay?.close(), new Promise((r) => setTimeout(r, 500))]);
26 await Promise.race([simulation?.close(), new Promise((r) => setTimeout(r, 500))]);
27 rmSync(dir, { recursive: true, force: true });
28 });
29
30 test("every item passes against a relay on the simulated arm", async () => {
31 const results = await runChecks(`http://127.0.0.1:${relay.port}`);
32 expect(results.length).toBe(7);
33 expect(results.filter((r) => !r.ok)).toEqual([]);

Add a case where a check fails for one reason only, e.g. a relay with no identity key where the forged-identity item must FAIL. The dead-address test cannot tell a working check from one that always fails.

34 });
35
36 test("a dead address fails every item", async () => {
37 const results = await runChecks("http://127.0.0.1:1");
38 expect(results.every((r) => !r.ok)).toBe(true);
39 });
Software/so101/bench/launch-check.ts added +129
@@ -0,0 +1,129 @@
1 /**
2 * Checks a deployed arm as an anonymous visitor and prints one PASS/FAIL line per item:
3 * bun run bench/launch-check.ts <url> exits 1 on any FAIL
4 * It signs in as nobody. The only commands it sends are POSTs that must be refused, and it confirms they were.
5 */
6 export interface Result {
7 name: string;
8 ok: boolean;
9 detail: string;
10 }
11
12 const FORGED = { "x-forge-identity": "u1|mallory|owner|99999999999999", "x-forge-signature": "AAAA" };
13 const REFUSED = new Set([401, 403]);
14
15 async function get(base: string, path: string, headers: Record<string, string> = {}) {
16 return fetch(base + path, { headers, redirect: "manual", signal: AbortSignal.timeout(5000) });
17 }
18
19 /** Open /live, resolve with the messages that arrive within `ms` (stopping early once `until` accepts one). */
20 function live(base: string, headers: Record<string, string>, until: (m: Record<string, unknown>) => boolean, ms: number): Promise<Record<string, unknown>[]> {
21 return new Promise((resolve, reject) => {
22 const url = new URL("/live", base);
23 url.protocol = url.protocol === "https:" ? "wss:" : "ws:";

The as never cast removes type checking here, and bench/ is not in tsconfig anyway. Fine for now, but it is the first thing to break unnoticed.

24 const seen: Record<string, unknown>[] = [];
25 const ws = new WebSocket(url, { headers } as never);
26 const done = () => {
27 clearTimeout(timer);
28 ws.close();
29 resolve(seen);
30 };
31 const timer = setTimeout(done, ms);
32 ws.onerror = () => {
33 clearTimeout(timer);
34 reject(new Error("/live did not open"));
35 };
36 ws.onmessage = (e) => {
37 try {
38 const m = JSON.parse(String(e.data)) as Record<string, unknown>;
39 seen.push(m);
40 if (until(m)) done();
41 } catch {
42 // not JSON: ignore
43 }
44 };
45 });
46 }
47
48 type Check = [string, (base: string) => Promise<string>];
49
50 const checks: Check[] = [
51 [
52 "/ is server-rendered with the security headers",
53 async (base) => {
54 const res = await get(base, "/");
55 if (res.status !== 200) throw new Error(`status ${res.status}`);
56 const body = await res.text();
57 if (!/<title>[^<]+<\/title>/.test(body) || !/<body[\s>]/.test(body)) throw new Error("no rendered page in the body");
58 for (const h of ["content-security-policy", "x-content-type-options", "referrer-policy"]) if (!res.headers.get(h)) throw new Error(`no ${h}`);
59 return "200";
60 },
61 ],
62 [
63 "/status answers",
64 async (base) => {
65 const res = await get(base, "/status");
66 const body = (await res.json().catch(() => ({}))) as { error?: unknown };
67 if (res.status === 200) return "200";
68 if (res.status === 503 && typeof body.error === "string" && body.error) return `503 ${body.error}`;
69 throw new Error(`status ${res.status}`);
70 },
71 ],
72 [
73 "/live opens and pushes a status within 2 s",
74 async (base) => {
75 const t = Date.now();
76 const got = await live(base, {}, (m) => m.type === "status", 2000);
77 if (!got.some((m) => m.type === "status")) throw new Error("no status message in 2 s");
78 return `${Date.now() - t} ms`;
79 },
80 ],
81 ...["/move", "/torque", "/stop"].map((path): Check => [
82 `anonymous POST ${path} is refused`,
83 async (base) => {
84 const res = await fetch(base + path, { method: "POST", headers: { "content-type": "application/json" }, body: "{}", signal: AbortSignal.timeout(5000) });
85 if (!REFUSED.has(res.status)) throw new Error(`status ${res.status}`);
86 return String(res.status);
87 },
88 ]),
89 [
90 "a forged x-forge-identity signs no one in",
91 async (base) => {
92 const res = await fetch(base + "/move", { method: "POST", headers: { ...FORGED, "content-type": "application/json" }, body: "{}", signal: AbortSignal.timeout(5000) });
93 if (!REFUSED.has(res.status)) throw new Error(`POST /move answered ${res.status}`);
94 const got = await live(base, FORGED, (m) => m.type === "hello", 2000);
95 const hello = got.find((m) => m.type === "hello");
96 if (!hello) throw new Error("/live said no hello");
97 if (hello.you) throw new Error("/live signed the forged identity in");
98 return String(res.status);
99 },
100 ],
101 ];
102
103 export async function runChecks(base: string): Promise<Result[]> {
104 const out: Result[] = [];
105 for (const [name, run] of checks) {
106 try {
107 out.push({ name, ok: true, detail: await run(base) });
108 } catch (err) {
109 out.push({ name, ok: false, detail: (err as Error).message });
110 }
111 }
112 return out;
113 }
114
115 if (import.meta.main) {
116 const arg = process.argv[2];
117 let base: string;
118 try {
119 const url = new URL(arg ?? "");
120 if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error("not http");
121 base = url.origin;
122 } catch {
123 console.error("usage: bun run bench/launch-check.ts <http(s)://url>");
124 process.exit(2);
125 }
126 const results = await runChecks(base);
127 for (const r of results) console.log(`${r.ok ? "PASS" : "FAIL"} ${r.name} (${r.detail})`);
128 process.exit(results.every((r) => r.ok) ? 0 : 1);
129 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs