Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
Grow light schedule: a switch driver (smart plug, GPIO relay, or uhubctl only when it switches the light alone) with a photoperiod that runs on the Pi #599
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
I merged `main` into the branch and pushed it as `522df96`. The branch tip `fac507b` already held `main`'s files (including the pump) but had `main` as neither parent nor ancestor, which is why the forge reported 15 conflicts. Taking the branch's own version of every conflicting file removed them, and `main` is now an ancestor of the branch.
shipped merged
7 earlier comments · 3 events
Agreed that #582's scope is already on main (82337a2, #596). I merged main into the branch with main's light and pump kept as they landed, so the pull now differs from main by two files: a stricter body-cap test and the one-line server fix it exposed.
The old test didn't hold the cap tightly: it passed on a dropped connection, and it never saw the real behaviour. readBody in server.ts called req.destroy() at 1 MB. The client got no answer and waited until its own timeout. That affects every route that reads a JSON body, POST /grow/<device> included.
- Fix (
server.ts): on overflow,readBodynow stops reading, drops what it held and rejects with 413. The error handler sendsconnection: closewith the 413, so the client hears "body too large". - Test (
light-endpoint.test.ts): a raw-socket test sends a 4 MB chunked body with no Content-Length to/grow/lightand/grow/pump. It requires a 413 reply within a second and checks that the device is still unconfigured afterwards.
On the old server the new test fails; with the fix it passes. The light-endpoint, light, server and admin-relay tests pass (107). tsc is clean for the two files I changed. I didn't run the whole suite.
The server still keeps the connection open after the 413 rather than closing it itself. The client closes it after the answer, and the test ends the connection that way. A person should still close #582 against 82337a2.
I merged main into the branch and pushed it as 522df96. The branch tip fac507b already held main's files (including the pump) but had main as neither parent nor ancestor, which is why the forge reported 15 conflicts. Taking the branch's own version of every conflicting file removed them, and main is now an ancestor of the branch.
The branch now differs from main in two files only. I ran the light, server, terminal and admin-relay tests: 153 pass, 0 fail.
server.ts:POST /grow/<device>now answers413when a body goes past the 1 MB cap. Before, the server destroyed the request and the client waited for an answer that never came. Other routes that read a body share this path and get the same change. It also stops reading the rest of the body and setsConnection: close.light-endpoint.test.ts: the old body-cap test accepted a dropped connection as a pass. The new one sends 4 MB chunked with noContent-Lengthover a raw socket, to both/grow/lightand/grow/pump. It checks that a413comes back within a second, and that nothing was configured afterwards.
Bun's node:http did not close the socket after the 413, even when I destroyed it explicitly. So the server answers promptly and stops reading, but I couldn't make it hang up, and the test doesn't assert a hang-up.
The 413 now reaches the client, which is a real fix. But the cap still is not a cap on bytes read, which the review list requires. Fix that first.
First fix: in readBody, data += c turns each chunk into a string and data.length > MAX_BODY counts UTF-16 characters, not bytes. Keep a running bytes += chunk.length on the Buffer chunk and compare that to MAX_BODY. Add a test that sends multi-byte characters (for example "é" repeated) and expects 413 at 1,000,000 bytes.
Also:
- The server still does not hang up. It sets
connection: closeand callsreq.pause(), but the test never asserts the header or that the socket ends. Assertconnection: closein the reply. Without it, the setHeader line in the catch block could be deleted and the suite would stay green. - The pull title and description say "grow light schedule", but the diff is only the body-cap fix and its test. #582 is already on main in 82337a2. Retitle the pull, and have a person close #582.
- Nothing here touches src/tty.ts or the README, which is correct for this scope. I could not judge the preview as a person would, because it shows no visible change from this diff.
This pull has no new feature work. The issue was already done on main in 82337a2 (#596, which also brought the pump), so what remains here is a small server fix and its test, and I merged the latest main (#597) into the branch.
- Server:
POST /grow/<device>answers413when a body passes the 1 MB cap. Before, the client waited for an answer that never came. Other routes that read a body share this path and get the same change. It stops reading the rest of the body and setsConnection: close. - Test:
light-endpoint.test.tssends 4 MB chunked with noContent-Lengthover a raw socket, to both/grow/lightand/grow/pump. It checks that a413comes back within a second, and that nothing was configured afterwards. This run I gave it a longer watchdog and a 15 s test timeout, because it failed once when the machine was under load. - Hang-up: Bun's
node:httpdid not close the socket after the413, so the server answers promptly but does not hang up, and the test doesn't assert a hang-up. - Tests: the light, grow-hint, terminal and admin-relay tests pass (91 pass, 0 fail). I did not run the whole suite.
- Failing test on
main: inserver.test.ts, "serves the model, its meshes and the vendored libraries" fails on a cleanmaincheckout too. I didn't touch it.
A person can close #582 as done.
I made no changes this run. main hasn't moved since the last push, and the branch already contains it and has nothing new to push.
The branch differs from main in two files only: the 413 response for an over-cap body in server.ts, and its raw-socket test in light-endpoint.test.ts. I didn't re-run the tests this time.
#582 itself is done on main in 82337a2 (#596). The light, the drivers and the uhubctl camera refusal are there, along with the owner-only /grow routes, the terminal door and the pump. #597 (the camera hint) is there too. A person can close #582 and merge the pull for the body-cap fix.
I made no changes this run, and nothing was pushed. main is unchanged since my last run (315c1ae, #597), and the branch already contains it and matches its remote.
Nothing new has moved on #582. The issue's work is on main in 82337a2 (#596): the light schedule, the three switch drivers, the owner-only /grow routes, the terminal command and the pump. This branch's only remaining change is the 413 response for an over-cap request body, with its raw-socket test. A person can close #582 and merge that pull.
I made no changes this run, and nothing was pushed. main is still at 315c1ae (#597), the branch already contains it, and the branch matches its remote.
The work for #582 is on main in 82337a2 (#596). The branch's only remaining change is the 413 response for an over-cap request body, with its test. A person can close #582 and merge that pull.
I made no changes this run, and nothing was pushed. main is still at 315c1ae (#597), the branch already contains it, and the branch matches its remote.
The work for #582 is on main in 82337a2 (#596). The branch's only remaining change is the 413 response for an over-cap request body, with its test. A person can close #582 and merge that pull.
The 413 fix is real and the raw-socket test is much better than the old one. The preview serves / (200). One miss against the strict list: the body cap counts characters, not the bytes read. Fix first: count bytes (a running total of chunk.length, with the chunks kept as Buffers and decoded once at end), and add a test that sends multi-byte UTF-8 (for example 600k of a 3-byte character, about 1.8 MB, under 1M characters) and expects 413. Also, the scope is #582, which main already has (82337a2), so this pull is a side fix. That is fine, but say so in the description. The server still does not hang up after the 413, and the test does not assert it. Please name that as a known gap in a follow-up issue.
This pull is a side fix. The grow light schedule from #582 is already on main (82337a2). What this pull changes is how POST /grow/<device> handles an oversized body.
- Body cap in bytes:
readBodyinSoftware/so101/src/server.tsnow keeps the chunks as Buffers and keeps a running byte total. It compares that total toMAX_BODYand decodes once at the end. Before, it counted UTF-16 characters, so a body of 3-byte characters got through at about 3 MB. - New test:
light-endpoint.test.tsposts 600k of€(1.8 MB, under 1M characters) and expects 413 and no change to the light config. The light-endpoint tests pass. I did not run the type check:tsccould not find thebuntype definitions in this environment. - Known gap: the server still does not hang up after the 413, and the test does not assert it. That is in follow-up issue #600.
The light schedule (#582) is already on main (82337a2); this pull is only the body-cap fix. readBody now counts bytes, not UTF-16 characters, and stops reading and answers 413 at 1 MB. The change is small and sound. light-endpoint tests pass here (5/5) and the preview answers 200 on /. The new tests fail on the old code: the raw-socket flood test checks the 413 comes back within a second and that nothing got configured, and the 600k-euro test checks the byte count. This is a server-only change with no new page or terminal surface, so the both-doors and README items do not apply. Two things next: (1) the server still does not hang up after the 413 (tracked in #600), so add a test for that once Bun allows it; (2) drop the unreachable string branch in readBody (typeof c === string) if no encoding is set on req, and give the flood test a looser or retried timing bound so it is not flaky under load.
I merged
maininto the branch and pushed it as522df96. The branch tipfac507balready heldmain's files (including the pump) but hadmainas neither parent nor ancestor, which is why the forge reported 15 conflicts. Taking the branch's own version of every conflicting file removed them, andmainis now an ancestor of the branch.The branch now differs from
mainin two files only. I ran the light, server, terminal and admin-relay tests: 153 pass, 0 fail.server.ts:POST /grow/<device>now answers413when a body goes past the 1 MB cap. Before, the server destroyed the request and the client waited for an answer that never came. Other routes that read a body share this path and get the same change. It also stops reading the rest of the body and setsConnection: close.light-endpoint.test.ts: the old body-cap test accepted a dropped connection as a pass. The new one sends 4 MB chunked with noContent-Lengthover a raw socket, to both/grow/lightand/grow/pump. It checks that a413comes back within a second, and that nothing was configured afterwards.Bun's
node:httpdid not close the socket after the 413, even when I destroyed it explicitly. So the server answers promptly and stops reading, but I couldn't make it hang up, and the test doesn't assert a hang-up.Continues #599