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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

/status names who is driving, including the owner after a take-over #174

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/160-status-names-who-is-driving-including-th → main 2 commits fork 2 threads · 2 unresolved

  • Merged. smith/160-status-names-who-is-driving-including-th was merged into main as 4eb94fb.

Review

Sign in to review this change.
5 files changed +47 −3
Software/README.md +5 −1
@@ -226,7 +226,11 @@ into the page (`<script type="application/json" id="boot">`), so the camera
226226 starts as soon as the script runs. The arm's limits, settings, poses and
227227 model are all requested at once after that. One WebSocket, `/live`, carries
228228 the turn, the queue, the chat and the arm's status. The status is pushed only
229 when it changes, so a page whose socket is open doesn't poll `/status`. A new
229 when it changes, so a page whose socket is open doesn't poll `/status`. `/status` and that push both carry
230 `driver`: `{id, name, owner}` of whoever holds the turn, or `null` when nobody
231 does. The owner shows as driving after a take-over. A 503 while the arm link
232 is reconnecting has no status and so no `driver`. The terminal (`src/tty.ts`)
233 has no status view, so there is nothing to add there. A new
230234 page gets the last 30 chat lines; **Earlier messages** fetches 50 more at a
231235 time. The camera follows the connection (`src/ui/camera-plan.js`). On a slow
232236 link (round trips over 400 ms, or the browser reporting 3G or a low
Software/so101/src/admin-relay.test.ts +18
@@ -102,3 +102,21 @@ test("reading /link never changes anything; the arm server switches when the set
102102 expect(after.host).toBe("127.0.0.1:1");
103103 expect(await (await fetch(`${base}/link`)).json()).toEqual(after);
104104 });
105
106 test("/status names who is driving: null, then alice, then the owner after a take-over", async () => {

This only covers GET /status. Add the /live push, which is the other path through statusOf, and check that a reconnecting 503 carries no driver.

107 const sim = Bun.serve({ port: 0, fetch: () => Response.json({ joints: [] }) });
108 try {
109 dir = mkdtempSync(join(tmpdir(), "so101-admin-relay-"));
110 lobby = new Lobby({ identityKey: KEY, adminFile: join(dir, "admin.json") });
111 relay = await startRelay({ port: 0, simulation: `http://127.0.0.1:${sim.port}`, lobby });
112 const base = `http://127.0.0.1:${relay.port}`;
113 const driver = async () => ((await (await fetch(`${base}/status`)).json()) as { driver: unknown }).driver;
114 expect(await driver()).toBeNull();
115 lobby.takeControl({ id: "id-alice", name: "alice", owner: false });
116 expect(await driver()).toEqual({ id: "id-alice", name: "alice", owner: false });
117 lobby.takeControl({ id: "id-trevato", name: "trevato", owner: true });
118 expect(await driver()).toEqual({ id: "id-trevato", name: "trevato", owner: true });
119 } finally {
120 sim.stop(true);
121 }
122 });
Software/so101/src/lobby.test.ts +12
@@ -329,6 +329,18 @@ describe("lobby", () => {
329329 expect((await moved).status.joints[0].position).toBe(first.status.joints[0].position + 100);
330330 });
331331
332 test("the status pushed on /live names the driver, and pushes again when the turn changes hands", async () => {
333 const port = await start();
334 const watcher = await join(port);
335 expect((await watcher.first((m) => m.type === "status")).status.driver).toBeNull();
336 const alice = await join(port, ALICE);
337 alice.send({ type: "join" });
338 expect((await watcher.next((m) => m.type === "status" && m.status.driver?.name === "alice")).status.driver).toEqual({ id: "u-alice", name: "alice", owner: false });
339 const owner = await join(port, OWNER);
340 owner.send({ type: "join" });
341 expect((await watcher.next((m) => m.type === "status" && m.status.driver?.owner === true)).status.driver).toEqual({ id: "u-owner", name: "trevato", owner: true });
342 });
343
332344 test("the driver and any admin may hit the emergency stop; only an admin clears it or changes the settings", async () => {
333345 const port = await start();
334346 const alice = await join(port, ALICE);
Software/so101/src/relay.test.ts +3 −1
@@ -233,7 +233,9 @@ describe("relay", () => {
233233 expect(l.problem).toContain("unreachable");
234234 const s = await fetch(`${base}/status`);
235235 expect(s.status).toBe(503);
236 expect(await s.json()).toMatchObject({ reconnecting: true, source: expect.stringContaining(`reconnecting to the arm: 127.0.0.1:${port}`) });
236 const refused = (await s.json()) as Record<string, unknown>;
237 expect(refused).toMatchObject({ reconnecting: true, source: expect.stringContaining(`reconnecting to the arm: 127.0.0.1:${port}`) });
238 expect("driver" in refused).toBe(false); // nothing to say about the turn when there is no status to say it in
237239 expect((await fetch(`${base}/move`, { method: "POST", body: '{"targets":{"1":2000}}' })).status).toBe(503);
238240 await sleep(650);
239241 expect((await link(base)).mode).toBe("offline");
Software/so101/src/relay.ts +9 −1
@@ -358,9 +358,17 @@ export async function startRelay(options: RelayOptions): Promise<RunningRelay> {
358358 const clocks = new Map<string, Clock>();
359359 /**
360360 * The arm's /status, saying which arm it is: from the link while it is live, the last one it had while reconnecting,
361 * and from the simulation otherwise.
361 * and from the simulation otherwise. It also adds `driver`, {id, name, owner} of whoever holds the turn (the owner
362 * after a take-over) or null, to every answer that has a status; the 503 has none. /status and the /live push share it.
362363 */
363364 const statusOf = async (path = "/status"): Promise<{ code: number; body: Record<string, unknown> }> => {
outdated

Name this wrapper's job in the doc comment above: it now also adds driver. The comment still describes only where the arm status comes from. ownStatus also has no comment of its own.

365 const answer = await ownStatus(path);
366 const d = lobby?.turns.snapshot().driver;
367 if (answer.code === 200) answer.body.driver = d ? { id: d.id, name: d.name, owner: d.owner } : null;
368 return answer;
369 };
370 /** The arm's status alone, with no word of the turn. */
371 const ownStatus = async (path: string): Promise<{ code: number; body: Record<string, unknown> }> => {
364372 if (onArm()) {
365373 const last = armLink!.last;
366374 const reconnecting = mode() === "reconnecting";

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs