A cable label is a field of the cable, so it survives the save (#1513) #1537

Merged
jaylouisw merged 1 commit from fix/1115-1935 into main 2026-11-15 20:22:16 +00:00
Owner

Fixes #1513

What was wrong. link.label = "via 0-LR-FP1 keystone 2" read back on the live Link and was written by nothing: Link.serialize() had no label, so Topology.serialize() dropped it and the annotation was gone at the next save. A property that accepts a value and keeps it nowhere is worse than a missing field, because it looks as if it worked.

What changed.

  • engine/link.js: label is a field of the Link (constructor, serialize()). It is written only when a cable has one, so a lab saved before the field existed produces the same document it always did. labelProblem() / normaliseLabel() hold the rule in one place: a label is a string, null/"" mean none, anything else is refused.
  • engine/topology.js: connect() takes opts.label and refuses a non-string with E_BAD_LABEL; fromJSON() restores it; cableProblem() reports E_LINK_BAD_LABEL for a document that states a label the Link cannot hold; new setLinkLabel().
  • server/index.js: POST /links passes label through; PATCH /links/:linkId applies one (it used to answer 200 and change nothing), and a label-only PATCH no longer touches the length.
  • docs/ARCHITECTURE.md: label added to the cable round-trip list and to the load-issue table.

Tests. test/link-roundtrip.test.js: a label survives save/reload and is in the document; connect() takes one; an unlabelled cable writes no key; a non-string is refused with E_BAD_LABEL and explained as E_LINK_BAD_LABEL when a document states one; over HTTP, a label comes back on the cable it made, a PATCH sets, keeps and clears one without disturbing the length, and a numeric label is refused with 409.

Suite: node scripts/syntax-check.js all OK; full node scripts/run-tests.js 251 suites, 9216 assertions, 0 failures.

Fixes #1513 **What was wrong.** `link.label = "via 0-LR-FP1 keystone 2"` read back on the live `Link` and was written by nothing: `Link.serialize()` had no `label`, so `Topology.serialize()` dropped it and the annotation was gone at the next save. A property that accepts a value and keeps it nowhere is worse than a missing field, because it looks as if it worked. **What changed.** - `engine/link.js`: `label` is a field of the `Link` (constructor, `serialize()`). It is written only when a cable has one, so a lab saved before the field existed produces the same document it always did. `labelProblem()` / `normaliseLabel()` hold the rule in one place: a label is a string, `null`/`""` mean none, anything else is refused. - `engine/topology.js`: `connect()` takes `opts.label` and refuses a non-string with `E_BAD_LABEL`; `fromJSON()` restores it; `cableProblem()` reports `E_LINK_BAD_LABEL` for a document that states a label the Link cannot hold; new `setLinkLabel()`. - `server/index.js`: `POST /links` passes `label` through; `PATCH /links/:linkId` applies one (it used to answer 200 and change nothing), and a label-only PATCH no longer touches the length. - `docs/ARCHITECTURE.md`: `label` added to the cable round-trip list and to the load-issue table. **Tests.** `test/link-roundtrip.test.js`: a label survives save/reload and is in the document; `connect()` takes one; an unlabelled cable writes no key; a non-string is refused with `E_BAD_LABEL` and explained as `E_LINK_BAD_LABEL` when a document states one; over HTTP, a label comes back on the cable it made, a PATCH sets, keeps and clears one without disturbing the length, and a numeric label is refused with 409. Suite: `node scripts/syntax-check.js` all OK; full `node scripts/run-tests.js` 251 suites, 9216 assertions, 0 failures.
A cable label is a field of the cable, so it survives the save (#1513)
All checks were successful
CI / Classify the change (pull_request) Successful in 18s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 17s
CI / Test (Node 18) (pull_request) Successful in 3m32s
CI / Test (Node 20) (pull_request) Successful in 3m10s
CI / Server smoke test (pull_request) Successful in 29s
CI / Docker build (pull_request) Successful in 45s
CI / Test (Node 22) (pull_request) Successful in 3m10s
80583f0f57
Setting a label on a live Link appeared to work and read back, and
`Topology.serialize()` wrote the link without it: the annotation - "via
0-LR-FP1 keystone 2", "USB Ethernet adapter", "DOWN - host decommissioned" -
was gone the moment the board was saved, and with it the whole cabling record.
A property the live object accepts and the serialiser drops is worse than a
missing field, because it looks like it worked.

`label` is now part of the Link: taken by `connect()`, written by `serialize()`
only when a cable has one (so a pre-existing lab writes the document it always
did), and restored by `fromJSON()`.

The value is either a string that is saved or it is refused where it is set:
`E_BAD_LABEL` from `connect()` and from the new `setLinkLabel()` /
`PATCH /api/topologies/:id/links/:linkId`, `E_LINK_BAD_LABEL` from the loader,
which explains the cable it could not keep the way it does for a state nobody
defines. `null` and `''` mean "no label".

`POST /links` passes a label through, and the PATCH door takes one: it used to
answer 200 for a request carrying a label and change nothing.

Tests in test/link-roundtrip.test.js, over the engine and over HTTP.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-15 20:17:19 +00:00
jaylouisw force-pushed fix/1115-1935 from 80583f0f57
All checks were successful
CI / Classify the change (pull_request) Successful in 18s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 17s
CI / Test (Node 18) (pull_request) Successful in 3m32s
CI / Test (Node 20) (pull_request) Successful in 3m10s
CI / Server smoke test (pull_request) Successful in 29s
CI / Docker build (pull_request) Successful in 45s
CI / Test (Node 22) (pull_request) Successful in 3m10s
to 5f9782bb1e
All checks were successful
CI / Classify the change (pull_request) Successful in 16s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 18s
CI / Test (Node 18) (pull_request) Successful in 3m26s
CI / Test (Node 20) (pull_request) Successful in 3m12s
CI / Server smoke test (pull_request) Successful in 36s
CI / Docker build (pull_request) Successful in 54s
CI / Test (Node 22) (pull_request) Successful in 3m15s
2026-11-15 20:17:22 +00:00
Compare
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-15 20:17:42 +00:00
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-15 20:22:00 +00:00
jaylouisw force-pushed fix/1115-1935 from 5f9782bb1e
All checks were successful
CI / Classify the change (pull_request) Successful in 16s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 18s
CI / Test (Node 18) (pull_request) Successful in 3m26s
CI / Test (Node 20) (pull_request) Successful in 3m12s
CI / Server smoke test (pull_request) Successful in 36s
CI / Docker build (pull_request) Successful in 54s
CI / Test (Node 22) (pull_request) Successful in 3m15s
to a90000dc75
All checks were successful
CI / Classify the change (pull_request) Successful in 15s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 18s
CI / Test (Node 20) (pull_request) Successful in 3m27s
CI / Test (Node 18) (pull_request) Successful in 3m37s
CI / Server smoke test (pull_request) Successful in 33s
CI / Docker build (pull_request) Successful in 45s
CI / Test (Node 22) (pull_request) Successful in 3m2s
2026-11-15 20:22:03 +00:00
Compare
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!1537
No description provided.