A door refuses all of a body, or applies all of it (#1425) #1426

Merged
jaylouisw merged 1 commit from fix/interface-door-atomic into main 2026-11-11 05:19:47 +00:00
Owner

Closes #1425.

POST /interfaces/:dev/:port writes four things — the address, enabled, description, and the cage's role — and wrote them as it went, answering 400 the moment one was refused:

{"ip":"10.9.9.9","mask":"255.255.255.0","role":"bogus"}   ->  400, and the address is stored

The caller is told the change failed while half of it happened. The board and the sentence about the board then disagree, and a person who reads "refused", reloads and finds a configured port cannot tell which to believe. #1413 promised this door "changes nothing on refusal" — true only when the refused field came first.

Fixed

case before now
address + impossible role 400, address stored 400, nothing written
{"enabled":"false"} 200, port enabled (!!"false" is true) 400 E_BAD_ENABLED, quoting "false"
{"enabled":0} 200, port enabled 400 E_BAD_ENABLED
{"description":42} 200, description 42 400 E_BAD_DESCRIPTION
five bad fields first reason only problems: [...], all four named, each with a code
role refusal 1 cannot be bogus (reads as a count) port 1 cannot be bogus

The address and its mask stay one field: an address that is not an address is refused before the mask is asked about, so the same field is never reported twice.

Evidence — 12 checks

test/interface-door-atomicity.test.js, against a real server on a managed switch:

  • nine refused bodies, each compared against a byte-identical snapshot of the port's configuration (address, mask, enabled, description, role, mode, VLANs) — the property is unchanged, not looks similar;
  • one body with five bad fields → 400 and four problems named back, all of them in the message, the address asked once;
  • five accepted bodies that must actually change the port — a door that refused everything would pass the first half;
  • and the refusals read like sentences: a port name, the value that was given, what a netmask is.

Reverting server/index.js fails 6 of 12, quoting the half-applied address, the 200s for "false"/0/42, the missing problems list and 1 cannot be bogus.

Suite: 213 suites, 8,090 assertions, 0 failed; syntax 281 files OK. Docs: docs/ARCHITECTURE.md, "A door refuses all of a body, or applies all of it".

Closes #1425. `POST /interfaces/:dev/:port` writes four things — the address, `enabled`, `description`, and the cage's role — and wrote them **as it went**, answering `400` the moment one was refused: ``` {"ip":"10.9.9.9","mask":"255.255.255.0","role":"bogus"} -> 400, and the address is stored ``` The caller is told the change failed while half of it happened. The board and the sentence about the board then disagree, and a person who reads "refused", reloads and finds a configured port cannot tell which to believe. #1413 promised this door *"changes nothing on refusal"* — true only when the refused field came first. ### Fixed | case | before | now | |---|---|---| | address + impossible role | `400`, address stored | `400`, nothing written | | `{"enabled":"false"}` | `200`, port **enabled** (`!!"false"` is `true`) | `400 E_BAD_ENABLED`, quoting `"false"` | | `{"enabled":0}` | `200`, port enabled | `400 E_BAD_ENABLED` | | `{"description":42}` | `200`, description `42` | `400 E_BAD_DESCRIPTION` | | five bad fields | first reason only | `problems: [...]`, all four named, each with a code | | role refusal | `1 cannot be bogus` (reads as a count) | `port 1 cannot be bogus` | The address and its mask stay one field: an address that is not an address is refused before the mask is asked about, so the same field is never reported twice. ### Evidence — 12 checks `test/interface-door-atomicity.test.js`, against a real server on a managed switch: - **nine refused bodies**, each compared against a byte-identical snapshot of the port's configuration (address, mask, enabled, description, role, mode, VLANs) — the property is *unchanged*, not *looks similar*; - one body with five bad fields → `400` and **four** problems named back, all of them in the message, the address asked once; - **five accepted bodies** that must actually change the port — a door that refused everything would pass the first half; - and the refusals read like sentences: a port name, the value that was given, what a netmask is. Reverting `server/index.js` fails **6 of 12**, quoting the half-applied address, the `200`s for `"false"`/`0`/`42`, the missing `problems` list and `1 cannot be bogus`. Suite: **213 suites, 8,090 assertions, 0 failed**; syntax 281 files OK. Docs: `docs/ARCHITECTURE.md`, "A door refuses all of a body, or applies all of it".
A door refuses all of a body, or applies all of it (#1425)
All checks were successful
CI / Classify the change (pull_request) Successful in 10s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 12s
CI / Test (Node 20) (pull_request) Successful in 2m52s
CI / Test (Node 18) (pull_request) Successful in 3m4s
CI / Server smoke test (pull_request) Successful in 28s
CI / Docker build (pull_request) Successful in 41s
CI / Test (Node 22) (pull_request) Successful in 2m45s
20074320f7
POST /interfaces/:dev/:port writes four things - the address, enabled, description and the cage's role - and it wrote them as it went, in that order, answering 400 the moment one was refused. Measured against a live server:

  {ip: 10.9.9.9, mask: 255.255.255.0, role: bogus}  ->  400, and the address is stored

The caller is told the change failed while half of it happened. After that the board and the sentence about the board disagree, and a person who reads 'refused', reloads and finds a configured port has no way to know which of the two to believe. #1413 promised this door 'changes nothing on refusal'; that held only when the refused field happened to come first.

Now every field is checked before any is written, and a refusal reports every problem in one response ({code, error, problems:[...]}) instead of the first. The address and its mask are one field: an address that is not an address is refused before the mask is asked about.

Two more questions in the same handler were being asked wrongly:

  {enabled: 'false'}  ->  200, and the port was ENABLED

because the door asked !!body.enabled, where a string is truthy. enabled is a boolean or a refusal now, and the refusal quotes what it was given. description accepted any type and is a string or a refusal. And a role refusal said '1 cannot be bogus', which reads as a count - it says 'port 1 cannot be bogus'.

Evidence: test/interface-door-atomicity.test.js, 12 checks. Nine refused bodies, each compared against a byte-identical snapshot of the port's configuration (address, mask, enabled, description, role, mode, VLANs); four problems named back from one body; five accepted bodies that must actually change the port - a door that refused everything would pass the first half. Reverting server/index.js fails 6 of 12, quoting the half-applied address, the 200s for 'false'/0/42, and the count-reading message. Suite: 213 suites, 8,090 assertions, 0 failed; syntax 281 files OK.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-11 05:19:44 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1426
No description provided.