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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

STOP can lose to a command already in flight: the relay must drop what it holds, and the Pi must refuse commands older than its last STOP #435

Merged opened this in answer to

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

Merged

smith/arm:smith/434-stop-can-lose-to-a-command-already-in-fl → main 3 commits fork 2 threads · 2 unresolved

  • Merged. smith/434-stop-can-lose-to-a-command-already-in-fl was merged into main as 930d8c0.

Review

Sign in to review this change.
8 files changed +128 −30
Software/so101/src/command-gate.test.ts +18 −2
@@ -10,8 +10,8 @@ const SKEW = 5_000_000;
1010
1111 describe("parseCommand", () => {
1212 test("reads the joints, and seq and t only when both are well formed", () => {
13 expect(parseCommand(frame(3, 1000))).toEqual({ seq: 3, t: 1000, joints: new Map([[1, 2000]]) });
14 expect(parseCommand('{"1": 2000}')).toEqual({ seq: null, t: null, joints: new Map([[1, 2000]]) });
13 expect(parseCommand(frame(3, 1000))).toEqual({ seq: 3, t: 1000, epoch: null, joints: new Map([[1, 2000]]) });
14 expect(parseCommand('{"1": 2000}')).toEqual({ seq: null, t: null, epoch: null, joints: new Map([[1, 2000]]) });
1515 for (const bad of ['{"1":2000,"seq":-1,"t":5}', '{"1":2000,"seq":1.5,"t":5}', '{"1":2000,"seq":1}', '{"1":2000,"seq":1,"t":"now"}', '{"1":2000,"seq":1,"t":0}'])
1616 expect(parseCommand(bad)).toMatchObject({ seq: null, t: null });
1717 expect(parseCommand("[1]")).toBeNull();
@@ -141,3 +141,19 @@ describe("a hold kept in a file", () => {
141141 expect(new CommandGate(f).held).toBeNull();
142142 });
143143 });
144
145 describe("STOP epoch", () => {
146 test("a frame stamped before the last STOP is refused whatever its seq and age; a newer or unstamped one is not", () => {
147 const gate = new CommandGate();
148 const now = 1_000_000;
149 const s = gate.open(new Clock(), false);
150 const f = (seq: number, epoch?: number) => JSON.stringify({ 1: 2000, seq, t: now, ...(epoch === undefined ? {} : { epoch }) });
151 expect(s.admit(f(1, 5), now)).toMatchObject({ ok: true });
152 gate.stopped(7);
153 gate.stopped(6); // never goes down
154 expect(gate.stopEpoch).toBe(7);
155 expect(s.admit(f(2, 6), now)).toEqual({ ok: false, drop: "before-stop" });
156 expect(s.admit(f(3, 7), now)).toMatchObject({ ok: true });
157 expect(s.admit(f(4), now)).toMatchObject({ ok: true }); // a sender with no epoch (the LAN leader) is not held to one
158 });
159 });
Software/so101/src/command-gate.ts +17 −3
@@ -8,6 +8,7 @@
88 * replayed its seq is not above the last one this stream sent (a duplicate, or out of order)
99 * stale it is older than MAX_AGE_MS: it sat in a buffer somewhere and is no longer what the hand meant
1010 * before-resume it was sent before the latest resume, however it got here
11 * before-stop its epoch is below the epoch of the last STOP this gate was told of (see below)
1112 * unstamped it has no seq and t where they are required (behind the relay; the CLI leader on a LAN sends none)
1213 *
1314 * The page's clock is not the server's. Each sender keeps a `Clock`: the smallest gap seen between a frame's `t` and
@@ -32,12 +33,14 @@ export interface Held {
3233 at: string;
3334 }
3435
35 export type Drop = "malformed" | "unstamped" | "replayed" | "held" | "stale" | "before-resume";
36 export type Drop = "malformed" | "unstamped" | "replayed" | "held" | "stale" | "before-resume" | "before-stop";
3637 export type Verdict = { ok: true; joints: Map<number, number> } | { ok: false; drop: Drop };
3738
3839 export interface Command {
3940 seq: number | null;
4041 t: number | null;
42 /** The relay's STOP epoch when it sent the frame; null from a sender that has none (the CLI leader on a LAN). */
43 epoch: number | null;
4144 joints: Map<number, number>;
4245 }
4346
@@ -45,9 +48,9 @@ export interface Command {
4548 export function parseCommand(text: string): Command | null {
4649 const joints = parseFrame(text);
4750 if (!joints) return null;
48 const { seq, t } = JSON.parse(text) as { seq?: unknown; t?: unknown };
51 const { seq, t, epoch } = JSON.parse(text) as { seq?: unknown; t?: unknown; epoch?: unknown };
4952 const stamped = Number.isSafeInteger(seq) && (seq as number) >= 0 && typeof t === "number" && Number.isFinite(t) && t > 0;
50 return { seq: stamped ? (seq as number) : null, t: stamped ? (t as number) : null, joints };
53 return { seq: stamped ? (seq as number) : null, t: stamped ? (t as number) : null, epoch: Number.isSafeInteger(epoch) && (epoch as number) >= 0 ? (epoch as number) : null, joints };
5154 }
5255
5356 /** One sender's clock, seen from here: when a frame it stamped would have arrived had nothing held it up. */
@@ -103,6 +106,11 @@ export class CommandGate {
103106 held: Held | null = null;
104107 /** When the arm was last resumed, on this clock, ms; frames sent before it never count. */
105108 private resumedAt = 0;
109 /**
110 * The newest STOP epoch seen. The relay numbers its STOPs with a rising epoch, carries it on the STOP and stamps it on
111 * every frame it forwards; a frame from before that STOP is refused here however late the network delivers it.
112 */
113 stopEpoch = 0;
106114 private readonly streams = new Set<GateStream>();
107115 private readonly file: string | undefined;
108116
@@ -131,6 +139,11 @@ export class CommandGate {
131139 return true;
132140 }
133141
142 /** A STOP carried this epoch: frames stamped with a lower one never count. Never goes down. */
143 stopped(epoch: unknown): void {
144 if (Number.isSafeInteger(epoch) && (epoch as number) > this.stopEpoch) this.stopEpoch = epoch as number;
145 }
146
134147 /** Answers whether it was held. Nothing moves until a frame sent after this comes in. Not held, it changes nothing. */
135148 resume(now = Date.now()): boolean {
136149 if (!this.held) return false;
@@ -175,6 +188,7 @@ export class GateStream {
175188 admit(text: string, now = Date.now()): Verdict {
176189 const c = parseCommand(text);
177190 if (!c) return { ok: false, drop: "malformed" };
191 if (c.epoch !== null && c.epoch < this.gate.stopEpoch) return { ok: false, drop: "before-stop" };
178192 if (c.seq === null || c.t === null) {
179193 if (this.stamped) return { ok: false, drop: "unstamped" };
180194 return this.gate.held ? { ok: false, drop: "held" } : { ok: true, joints: c.joints };
Software/so101/src/fake-serve.test.ts +3 −1
@@ -16,7 +16,9 @@ afterEach(() => {
1616
1717 /** Start the fake arm with this environment and wait for its "arm on http://host:port" line. */
1818 async function start(env: Record<string, string>): Promise<{ host: string; port: number; line: string }> {
19 child = Bun.spawn(["bun", "run", script], { env: { ...process.env, ...env }, stdout: "pipe", stderr: "inherit" });
19 // Hermetic: a cell's own ARM_SERVER (the real Pi) must never reach the child.
20 const inherited = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith("ARM_")));
21 child = Bun.spawn(["bun", "run", script], { env: { ...inherited, ...env }, stdout: "pipe", stderr: "inherit" });
2022 const reader = (child.stdout as ReadableStream<Uint8Array>).getReader();
2123 let text = "";
2224 while (!text.includes("\n")) {
Software/so101/src/frame-limit.test.ts +4 −2
@@ -10,6 +10,8 @@ import { FakeBus } from "./fake-bus.ts";
1010 import { BURST, FLOOD_CLOSE, FLOOD_MS, FrameRate, frameBytes, MAX_FRAME_BYTES, TOO_BIG_CLOSE } from "./frame-limit.ts";
1111 import { LOST_CLOSE, parseRemote, startRelay, type RunningRelay } from "./relay.ts";
1212 import { startServer, type RunningServer } from "./server.ts";
13 /** A frame as the arm sees it, without the STOP epoch the relay stamps on it. */
14 const unstamped = (frame: string) => JSON.stringify(Object.fromEntries(Object.entries(JSON.parse(frame) as object).filter(([key]) => key !== "epoch")));
1315
1416 const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
1517 const shut = (s: { close(): Promise<void> } | undefined) => (s ? Promise.race([s.close(), sleep(500)]) : undefined);
@@ -179,12 +181,12 @@ describe("the relay's /follow", () => {
179181 const stamp = stamper();
180182 arm.ws.send(stamp({ 1: 2050 }));
181183 await sleep(30);
182 expect(arm.got).toEqual(['{"1":2050}']);
184 expect(arm.got.map(unstamped)).toEqual(['{"1":2050}']);
183185 const code = closed(arm.ws);
184186 arm.ws.send(JSON.stringify({ 1: 2060, seq: 99, t: Date.now(), pad: "x".repeat(MAX_FRAME_BYTES) }));
185187 expect(await code).toBe(TOO_BIG_CLOSE);
186188 await sleep(30);
187 expect(arm.got).toEqual(['{"1":2050}']);
189 expect(arm.got.map(unstamped)).toEqual(['{"1":2050}']);
188190 expect(arm.ended).toEqual([1000]); // not LOST_CLOSE: the arm server holds rather than parks
189191 expect(arm.ended).not.toContain(LOST_CLOSE);
190192 } finally {
Software/so101/src/relay.test.ts +5 −3
@@ -13,6 +13,8 @@ import { FakeBus } from "./fake-bus.ts";
1313 import { OFFLINE_FRAME } from "./offline-frame.ts";
1414 import { parseRemote, sameOrigin, startRelay, type Remote, type RunningRelay } from "./relay.ts";
1515 import { startServer, type RunningServer } from "./server.ts";
16 /** A frame as the arm sees it, without the STOP epoch the relay stamps on it. */
17 const unstamped = (frame: string) => JSON.stringify(Object.fromEntries(Object.entries(JSON.parse(frame) as object).filter(([key]) => key !== "epoch")));
1618
1719 const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
1820 // Bun's node:http can keep a server-closed connection from ending (see server.test.ts): cap every close.
@@ -425,20 +427,20 @@ describe("relay", () => {
425427 const stamp = stamper();
426428 ws.send(stamp({ 1: 2050 }));
427429 await sleep(30);
428 expect(got).toEqual(['{"1":2050}']); // the joints alone: the stamps stay here
430 expect(got.map(unstamped)).toEqual(['{"1":2050}']); // the joints alone: the stamps stay here
429431 watching = false;
430432 await sleep(100);
431433 expect(relay.link().mode).toBe("reconnecting");
432434 ws.send(stamp({ 1: 2060 }));
433435 await sleep(30);
434 expect(got).toEqual(['{"1":2050}']); // the arm server's dead-man sees silence, and holds
436 expect(got.map(unstamped)).toEqual(['{"1":2050}']); // the arm server's dead-man sees silence, and holds
435437 expect(ws.readyState).toBe(WebSocket.OPEN);
436438 watching = true;
437439 await sleep(80);
438440 expect(relay.link().mode).toBe("live");
439441 ws.send(stamp({ 1: 2070 }));
440442 await sleep(30);
441 expect(got).toEqual(['{"1":2050}', '{"1":2070}']);
443 expect(got.map(unstamped)).toEqual(['{"1":2050}', '{"1":2070}']);
442444 ws.close();
443445 } finally {
444446 clearInterval(pump);
Software/so101/src/relay.ts +26 −8
@@ -620,17 +620,23 @@ export async function startRelay(options: RelayOptions): Promise<RunningRelay> {
620620
621621 if (req.method === "GET" && PAGE.test(url.pathname)) return await page(req, res, await ask(simulation + path, req, undefined, null, false));
622622 if (req.method === "GET" && STATIC.test(url.pathname) && acceptsGzip(req.headers)) return await packed(res, await ask(simulation + path, req, undefined, null, false), path);
623 // Who stopped or cleared the arm is the relay's to say, never the page's; every other command is held to the admin's speed cap.
624 const raw = reading || route === "POST /estop" || route === "POST /estop/clear" || route === "POST /stop" || route === "POST /resume" ? undefined : await readBody(req);
625 const body = reading ? undefined : !raw ? Buffer.from(JSON.stringify({ by })) : lobby ? capBody(url.pathname, raw, lobby.maxSpeedPercent) : raw;
626 const logged = !reading && !LOCAL.test(url.pathname);
627 if (logged) machine.note("sent", route, { by });
628 const answered = (status: number) => logged && machine.note("received", route, { status });
629623 if (route === "POST /stop") {
630624 // Shut before anything is asked of an arm: a frame already on its way finds the gate closed.
631625 gate.hold(by);
626 epoch = Math.max(epoch + 1, Date.now());
627 // Whatever the arm-side sockets have accepted but not written is dropped with them, ahead of the STOP. A clean close
628 // would flush that queue first, so it is cut. The arm server reads the cut as a lost driver and would park the arm,
629 // but it parks only while not held, and the STOP it is sent at once holds it and aborts a park under way; frames
outdated

terminate() is an unclean close. The arm server can read it as a lost driver instead of a deliberate close. Use a clean close (1000), or document what the Pi does.

terminate() means the Pi sees a lost driver and may begin a park before the STOP HTTP request arrives. The comment says the STOP aborts it, but no test pins that window. Add one, or send the STOP first.

630 // that did get out carry the old epoch, which it refuses once it has the STOP.
631 for (const arm of armSides.values()) arm.terminate();
632632 for (const browser of streams.keys()) browser.close(HELD_CLOSE, `stopped by ${by}`);
633633 }
634 // Who stopped or cleared the arm is the relay's to say, never the page's; every other command is held to the admin's speed cap.
635 const raw = reading || route === "POST /estop" || route === "POST /estop/clear" || route === "POST /stop" || route === "POST /resume" ? undefined : await readBody(req);
636 const body = reading ? undefined : !raw ? Buffer.from(JSON.stringify(route === "POST /stop" ? { by, epoch } : { by })) : lobby ? capBody(url.pathname, raw, lobby.maxSpeedPercent) : raw;
637 const logged = !reading && !LOCAL.test(url.pathname);
638 if (logged) machine.note("sent", route, { by });
639 const answered = (status: number) => logged && machine.note("received", route, { status });
634640 if (route === "POST /resume") return await resume(res, by);
635641 if (LOCAL.test(url.pathname) || !onArm() || !remote) {
636642 const answer = await ask(simulation + path, req, body, null, false);
@@ -681,6 +687,14 @@ export async function startRelay(options: RelayOptions): Promise<RunningRelay> {
681687 const sendable = (code: number) => (code >= 1000 && code <= 1003) || (code >= 1007 && code <= 1014) || (code >= 3000 && code <= 4999);
682688 /** Each open /follow stream and whose it is, so a turn that ends can close it. */
683689 const streams = new Map<WebSocket, string>();
690 /** The arm-side socket of each stream, so a STOP can cut what it has queued but not yet written. */
691 const armSides = new Map<WebSocket, WebSocket>();
692 /**
693 * The STOP epoch: rises with every STOP (and never repeats across a restart, being a clock to begin with). It rides on
694 * the STOP to the arm server and on every frame forwarded, so the arm server refuses a frame older than its last STOP
695 * however the network orders them.
696 */
697 let epoch = Date.now();
684698 /**
685699 * `base` is the arm server's HTTP side, asked where the joints are so the speed cap starts from there. On the real arm,
686700 * frames are not passed on while the link reconnects: the stream goes quiet, and the arm server's dead-man holds the arm.
@@ -688,11 +702,13 @@ export async function startRelay(options: RelayOptions): Promise<RunningRelay> {
688702 const bridge = (browser: WebSocket, arm: WebSocket, base: string, driver: string | null) => {
689703 const real = base !== simulation;
690704 streams.set(browser, driver ?? "");
705 armSides.set(browser, arm);
691706 const clock = clocks.get(driver ?? "") ?? new Clock();
692707 clocks.set(driver ?? "", clock);
693708 const admission = gate.open(clock, true);
694709 browser.on("close", () => {
695710 streams.delete(browser);
711 armSides.delete(browser);
696712 admission.close();
697713 });
698714 arm.on("message", (data, binary) => browser.readyState === WebSocket.OPEN && browser.send(data, { binary }));
@@ -719,6 +735,8 @@ export async function startRelay(options: RelayOptions): Promise<RunningRelay> {
719735 /** A frame as the panel shows it: servo id → ticks. */
720736 const values = (text: string) => perServo(parseFrame(text) ?? []);
721737 const rate = new FrameRate();
738 /** A frame as it goes to the arm server: carrying the STOP epoch it was sent under. */
739 const stamped = (frame: string) => JSON.stringify({ ...(JSON.parse(frame) as object), epoch });
722740 /** Set when this relay ends the stream for breaking the limits: the arm then holds, as for a stream closed on purpose. */
723741 let overLimit = false;
724742 browser.on("message", (raw) => {
@@ -752,7 +770,7 @@ export async function startRelay(options: RelayOptions): Promise<RunningRelay> {
752770 if (percent >= 100) {
753771 if (lobby) cap.cap(text, percent); // keeps each joint's last target, so a cap set mid-stream starts from there
754772 machine.note("sent", "follow frame", { values: values(text) });
755 arm.send(data);
773 arm.send(stamped(data));
756774 return;
757775 }
758776 if (!seeded) seed();
@@ -760,7 +778,7 @@ export async function startRelay(options: RelayOptions): Promise<RunningRelay> {
760778 if (capped !== text) machine.note("clamp", "speed cap", { percent, asked: values(text), sent: capped === null ? {} : values(capped) });
761779 if (capped === null) return;
762780 machine.note("sent", "follow frame", { values: values(capped) });
763 arm.send(capped);
781 arm.send(stamped(capped));
764782 });
765783 arm.on("close", (code, why) => browser.close(sendable(code) ? code : 1011, why.length ? why.toString() : "the arm server went away"));
766784 // A browser that closed the stream on purpose leaves the arm holding; one that vanished leaves it parking.
Software/so101/src/server.ts +1
@@ -862,6 +862,7 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}):
862862 case "POST /stop": {
863863 const body = await readBody(req);
864864 // Held first, before anything awaits: a frame already on its way finds the gate shut.
865 gate.stopped(body.epoch);

This line is the Pi half of the fix and no test covers it. Add a server-level test that fails when this line is removed.

865866 if (body.hold !== false && gate.hold(actor(body))) metrics.event("hold", { by: actor(body) });
866867 const was = driver;
867868 if (was === "stream") for (const client of wss.clients) end(client, 1000, "stopped from the viewer"); // its close handler holds the arm
Software/so101/src/stop.test.ts +54 −11
@@ -42,16 +42,25 @@ class FakePi {
4242 readonly got: Array<{ at: number; n: number }> = [];
4343 readonly http: Server;
4444 port = 0;
45 stopEpoch = 0;
4546 #pump: ReturnType<typeof setInterval> | undefined;
4647 private readonly timeline: Entry[];
47 constructor(timeline: Entry[]) {
48 /** A slow link to the relay: each frame is taken this long after it came in; a STOP is not delayed. */
49 private readonly linkMs: number;
50 constructor(timeline: Entry[], linkMs = 0) {
4851 this.timeline = timeline;
52 this.linkMs = linkMs;
4953 const follow = new WebSocketServer({ noServer: true });
5054 const watch = new WebSocketServer({ noServer: true });
5155 this.http = createServer((req, res) => {
52 req.resume();
56 const chunks: Buffer[] = [];
57 req.on("data", (c: Buffer) => chunks.push(c));
5358 req.on("end", () => {
5459 if (req.method === "POST") this.timeline.push({ at: Date.now(), who: "pi", what: `POST ${req.url}` });
60 if (req.method === "POST" && req.url === "/stop") {
61 const epoch = (JSON.parse(Buffer.concat(chunks).toString() || "{}") as { epoch?: unknown }).epoch;
62 if (typeof epoch === "number") this.stopEpoch = Math.max(this.stopEpoch, epoch);
63 }
5564 res.writeHead(200, { "content-type": "application/json" });
5665 res.end(req.url === "/status" ? JSON.stringify(this.status) : "{}");
5766 });
@@ -62,9 +71,16 @@ class FakePi {
6271 to.handleUpgrade(req, socket, head, (ws) => {
6372 if (to !== follow) return;
6473 ws.on("message", (d) => {
65 const n = Number(JSON.parse(String(d))["1"]) - 1000;
66 this.got.push({ at: Date.now(), n });
67 this.timeline.push({ at: Date.now(), who: "pi", what: `target #${n}`, n });
74 const frame = JSON.parse(String(d)) as { "1": number; epoch?: number };
75 const n = frame["1"] - 1000;
76 // Like the real server: a frame stamped before the last STOP it heard of is refused, however late it comes.
77 const take = () => {
78 if (typeof frame.epoch === "number" && frame.epoch < this.stopEpoch) return void this.timeline.push({ at: Date.now(), who: "pi", what: `refused #${n} (before STOP)`, n });
79 this.got.push({ at: Date.now(), n });
80 this.timeline.push({ at: Date.now(), who: "pi", what: `target #${n}`, n });
81 };
82 if (this.linkMs) setTimeout(take, this.linkMs);
83 else take();
6884 });
6985 });
7086 });
@@ -167,9 +183,9 @@ describe("STOP through the relay, to a Pi that holds nothing itself", () => {
167183 pi?.close();
168184 relay = lobby = undefined;
169185 });
170 const start = async () => {
186 const start = async (linkMs = 0) => {
171187 timeline = [];
172 pi = new FakePi(timeline);
188 pi = new FakePi(timeline, linkMs);
173189 const piPort = await pi.listen();
174190 lobby = new Lobby({ identityKey: KEY });
175191 relay = await startRelay({ port: 0, simulation: `http://127.0.0.1:${simulation.port}`, remote: parseRemote({ ARM_SERVER: `ws://127.0.0.1:${piPort}` })!, link: FAST, lobby });
@@ -213,10 +229,9 @@ describe("STOP through the relay, to a Pi that holds nothing itself", () => {
213229 print("(b) replay: 100 commands while held, STOP, resume", timeline);
214230 });
215231
216 test("(a) any interleaving of drag, slider, STOP, resume, disconnect and turn change: nothing reaches the Pi between a STOP and a resume plus a new command", async () => {
217 const SEEDS = 8, STEPS = 40;
232 const interleavings = async (linkMs: number, SEEDS: number, STEPS: number) => {
218233 for (let seed = 1; seed <= SEEDS; seed++) {
219 const port = await start();
234 const port = await start(linkMs);
220235 const random = mulberry32(seed);
221236 const pages = [new Page("alice", person("alice"), () => port, timeline), new Page("bob", person("bob"), () => port, timeline)];
222237 lobby!.turns.join({ id: "u-alice", name: "alice", owner: false });
@@ -297,7 +312,11 @@ describe("STOP through the relay, to a Pi that holds nothing itself", () => {
297312 pi.close();
298313 relay = lobby = undefined;
299314 }
300 }, 120_000);
315 };
316
317 test("(a) any interleaving of drag, slider, STOP, resume, disconnect and turn change: nothing reaches the Pi between a STOP and a resume plus a new command", () => interleavings(0, 8, 40), 120_000);
318
319 test("(c) the same on a slow Pi link (each write lands 50 ms late): a frame in flight when STOP is pressed is refused by the Pi", () => interleavings(50, 4, 30), 120_000);
301320 });
302321
303322 describe("STOP on the arm server itself", () => {
@@ -361,6 +380,30 @@ describe("STOP on the arm server itself", () => {
361380 await sleep(50);
362381 });
363382
383 test("a STOP carrying an epoch makes the server refuse any frame stamped before it, even after a resume: frames from the relay's queue never move the arm", async () => {
384 const N = Date.now() + 1_000_000;
385 const first = await stream();
386 first.send(JSON.stringify({ 1: 2100, seq: 1, t: Date.now(), epoch: N - 5 }));
387 await sleep(100);
388 expect(await (await post("/stop", { by: "relay", epoch: N })).json()).toEqual({ stopped: "stream" });
389 await sleep(100); // the stream's close settles the arm where it is
390 expect((await post("/resume", { by: "relay" })).status).toBe(200);
391 const from = fake.writes.length;
392 const s = await stream();
393 // stamped before the STOP, however fresh its seq and t: refused
394 s.send(JSON.stringify({ 1: 2300, seq: 1, t: Date.now(), epoch: N - 1 }));
395 await sleep(100);
396 expect(goals(from).filter((w) => w.address === 42 && w.id === 1)).toEqual([]);
397 // stamped at or after the STOP: goes
398 s.send(JSON.stringify({ 1: 2150, seq: 2, t: Date.now(), epoch: N }));
399 await sleep(100);
400 const moved = goals(from).filter((w) => w.address === 42 && w.id === 1).map((w) => w.bytes[0]! | (w.bytes[1]! << 8));
401 expect(moved).toContain(2150);
402 expect(moved).not.toContain(2300);
403 s.close();
404 await sleep(50);
405 });
406
364407 test("a turn that ends stops what drives without holding", async () => {
365408 const ws = await stream();
366409 ws.send(JSON.stringify({ 1: 2100 }));

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs