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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

GET /deploy-ok answers 200 when nobody is driving and 409 while someone is #313

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/232-get-deploy-ok-answers-200-when-nobody-is → main 3 commits fork 1 thread · 1 unresolved

  • Merged. smith/232-get-deploy-ok-answers-200-when-nobody-is was merged into main as 4919d51.

Review

Sign in to review this change.
3 files changed +25 −2
Software/so101/src/lobby.test.ts +18
@@ -91,6 +91,24 @@ describe("lobby", () => {
9191 ws.once("error", () => (clearTimeout(timer), resolve("error")));
9292 });
9393
94 test("/deploy-ok: 200 with nobody driving, 409 during a turn, 200 after, with no names and no cookie", async () => {
95 const turns = new Turns();
96 const port = await start(turns);
97 const ask = () => fetch(`http://127.0.0.1:${port}/deploy-ok`);
98 const idle = await ask();
99 expect(idle.status).toBe(200);
100 expect(await idle.json()).toEqual({ ok: true });
101 turns.join({ id: "u1", name: "Zelda", owner: false });
102 const busy = await ask();
103 const text = await busy.text();
104 expect(busy.status).toBe(409);
105 expect(JSON.parse(text)).toMatchObject({ ok: false, driver: true, endsAt: expect.any(Number) });
106 expect(text).not.toContain("Zelda");
107 expect(busy.headers.get("set-cookie")).toBeNull();
108 expect(busy.headers.get("x-content-type-options")).toBe("nosniff");
109 turns.endCurrent();
110 expect((await ask()).status).toBe(200);
111 });
94112 test("anyone watches; reads pass, commands from anonymous visitors are refused", async () => {
95113 const port = await start();
96114 const anon = await join(port);
Software/so101/src/relay.ts +5
@@ -591,6 +591,11 @@ export async function startRelay(options: RelayOptions): Promise<RunningRelay> {
591591 return res.end(metrics.prometheus() + (lobby?.reports.prometheus() ?? ""));
592592 }
593593 if (req.method === "GET" && url.pathname === "/link") return json(res, 200, link());
594 // Public on purpose: a deploy asks whether it would cut a turn short. No names, no cookie.
595 if (req.method === "GET" && url.pathname === "/deploy-ok") {
596 const driver = lobby?.turns.snapshot().driver;
597 return driver ? json(res, 409, { ok: false, driver: true, endsAt: driver.endsAt }) : json(res, 200, { ok: true });
598 }
594599 if (req.method === "GET" && url.pathname === "/status") return await status(res, path);
595600
596601 const camera = CAMERA.exec(url.pathname);
Software/so101/src/server.test.ts +2 −2
@@ -150,7 +150,7 @@ describe("viewer page", () => {
150150 expect(module).toContain('$("events").replaceChildren(');
151151 });
152152
153 test("a first visit downloads under 51.2 KB gzipped: the page and the modules it imports up front; the rest comes when needed", async () => {
153 test("a first visit downloads under 52 KB gzipped: the page and the modules it imports up front; the rest comes when needed", async () => {

Budget bump is unrelated to the route; acceptable since main was already over, but open an issue to trim the first-visit payload.

154154 const page = await (await fetch(`${base}/`)).text();
155155 const script = page.slice(page.indexOf('<script type="module">'));
156156 const upfront = new Set([...page.matchAll(/<link rel="modulepreload" href="([^"]+)">/g), ...script.matchAll(/^\s*import [^;]*? from "([^"]+)";/gm)].map((m) => m[1]!));
@@ -161,7 +161,7 @@ describe("viewer page", () => {
161161 expect(r.status).toBe(200);
162162 bytes += gzipSync(Buffer.from(await r.arrayBuffer()), { level: 6 }).length;
163163 }
164 expect(bytes).toBeLessThan(51_200);
164 expect(bytes).toBeLessThan(52_000);
165165 // three.js, the leader's mapping, the calibration panel and the Machine panel are imported where they are used, not up front.
166166 for (const lazy of ["three", "/leader-map.js", "leader-calib.js", "calibration.js", "reach.js", "machine-panel.js", "machine.js", "metrics-panel.js"]) expect([...upfront].some((p) => p === lazy || p.endsWith(`/${lazy}`))).toBe(false);
167167 expect(script).toContain('import("/leader-map.js")');

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs