A forced line rate survives a save, and so does the test that missed it (#1405) #1406

Merged
jaylouisw merged 1 commit from fix/forced-rate-survives-save into main 2026-11-11 00:47:18 +00:00
Owner

A forced line rate survives a save, and so does the test that missed it. Fixes #1405.

Found by asking the save question from the other end: not "does the document reload as itself" but "set one thing,
save, reload, and diff the port object field by field". The answer for speed 100 was that the field is gone.

sw1(config-if)#speed 100
Speed 100M on Gi1/0/1
sw1#show interfaces Gi1/0/1
  speed: 100Mb/s (forced), duplex: full
sw1#show running-config
  speed 100

Save and reload: the port is back at its hardware rate, and speed 100 has gone from running-config as well — which
is what made it permanent, because nothing was left to put it back. duplex, one line above it in both the writer
and the reader, was saved all along.

Why the existing guarantee missed it

test/port-roundtrip.test.js round-tripped a lab straight out of the catalogue, so every field sat at its default
and the comparison was default-in, default-out. A setting that is only non-default after a command is invisible to
a sweep over virgin labs.
The section's own claim — "every field of every port survives the round trip, for every
model in the catalogue" — was tested against a file that carried nothing.

What changed

  • Device.serialize() writes speedMbps when the rate has been forced, and only then, following the file's own rule
    for optional facts (natRole, the combo fields): a port that negotiates its own rate must not grow a
    speedMbps: null line, and a board must not grow one on every port in the catalogue.
  • fromJSON() restores it beside duplex, so show interfaces says 100Mb/s (forced), running-config still prints
    speed 100, and the link itself runs at 100 after the reload — the value the engine uses, not just a field.

Evidence

test/port-roundtrip.test.js gained two sections — 32 checks in the suite. The sweep now configures first:
one port of every model with a speed ladder is forced to its lowest supported rate (1,902 of 2,038 models),
saved, reloaded, and every field of every port compared. Then the specific case: the saved document carries the rate;
the reloaded port still has it; show interfaces and running-config both still say so; the cable between two 1 Gbps
ports runs at 100 before and after the reload; speed auto clears it with no stale rate left in the file; a virgin
port's document still contains no speedMbps at all; and save → load → save is byte-identical.

Reverting engine/device.js fails 5 of the 32, naming the models whose rate was lost.

docs/ARCHITECTURE.md: speedMbps added to the lost-on-reload table, plus why a virgin-lab sweep cannot see a
setting, and the two conventions (unset fields are not written; a cache the file drops is checked by behaviour — the
reloaded port must still classify into the same VLAN). docs/CLI.md: the forced rate survives a save.

Suite: 204 suites, 7,869 assertions, 0 failed. Syntax: 272 files, OK.

A forced line rate survives a save, and so does the test that missed it. Fixes #1405. Found by asking the save question from the other end: not "does the document reload as itself" but "set one thing, save, reload, and diff the port object field by field". The answer for `speed 100` was that the field is gone. ``` sw1(config-if)#speed 100 Speed 100M on Gi1/0/1 sw1#show interfaces Gi1/0/1 speed: 100Mb/s (forced), duplex: full sw1#show running-config speed 100 ``` Save and reload: the port is back at its hardware rate, and `speed 100` has gone from running-config as well — which is what made it permanent, because nothing was left to put it back. `duplex`, one line above it in both the writer and the reader, was saved all along. ## Why the existing guarantee missed it `test/port-roundtrip.test.js` round-tripped a lab straight out of the catalogue, so every field sat at its default and the comparison was default-in, default-out. **A setting that is only non-default after a command is invisible to a sweep over virgin labs.** The section's own claim — "every field of every port survives the round trip, for every model in the catalogue" — was tested against a file that carried nothing. ## What changed * `Device.serialize()` writes `speedMbps` when the rate has been forced, and only then, following the file's own rule for optional facts (`natRole`, the combo fields): a port that negotiates its own rate must not grow a `speedMbps: null` line, and a board must not grow one on every port in the catalogue. * `fromJSON()` restores it beside `duplex`, so `show interfaces` says `100Mb/s (forced)`, running-config still prints `speed 100`, and the link itself runs at 100 after the reload — the value the engine uses, not just a field. ## Evidence `test/port-roundtrip.test.js` gained two sections — **32 checks** in the suite. The sweep now **configures** first: one port of every model with a speed ladder is forced to its lowest supported rate (**1,902 of 2,038 models**), saved, reloaded, and every field of every port compared. Then the specific case: the saved document carries the rate; the reloaded port still has it; `show interfaces` and running-config both still say so; the cable between two 1 Gbps ports runs at 100 before *and* after the reload; `speed auto` clears it with no stale rate left in the file; a virgin port's document still contains no `speedMbps` at all; and save → load → save is byte-identical. Reverting `engine/device.js` fails **5 of the 32**, naming the models whose rate was lost. `docs/ARCHITECTURE.md`: `speedMbps` added to the lost-on-reload table, plus why a virgin-lab sweep cannot see a setting, and the two conventions (unset fields are not written; a cache the file drops is checked by behaviour — the reloaded port must still classify into the same VLAN). `docs/CLI.md`: the forced rate survives a save. Suite: **204 suites, 7,869 assertions, 0 failed**. Syntax: 272 files, OK.
A forced line rate survives a save, and so does the test that missed it (#1405)
All checks were successful
CI / Classify the change (pull_request) Successful in 11s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 15s
CI / Test (Node 20) (pull_request) Successful in 2m58s
CI / Test (Node 18) (pull_request) Successful in 3m11s
CI / Server smoke test (pull_request) Successful in 28s
CI / Docker build (pull_request) Successful in 35s
CI / Test (Node 22) (pull_request) Successful in 2m25s
66785dfb7b
Found by asking the save question from the other end: not "does the document reload as itself" but "set one thing,
save, reload, and diff the port object field by field". The answer for `speed 100` was that the field is gone.

    sw1(config-if)#speed 100
    Speed 100M on Gi1/0/1
    sw1#show interfaces Gi1/0/1
      speed: 100Mb/s (forced), duplex: full
    sw1#show running-config
      speed 100

Then save and reload: the port is back at its hardware rate, and `speed 100` has gone from running-config as well -
which is what made it permanent, because nothing was left to put it back. `duplex`, one line above it in both the
writer and the reader, was saved all along.

Why the existing guarantee missed it: `test/port-roundtrip.test.js` round-tripped a lab straight out of the
catalogue, so every field sat at its default and the comparison was default-in, default-out. A setting that is only
non-default after a command is invisible to a sweep over virgin labs. The section's own claim - "every field of every
port survives the round trip, for every model in the catalogue" - was tested against a file that carried nothing.

Fixed:

* `Device.serialize()` writes `speedMbps` when the rate has been forced, and only then, following the file's own
  rule for optional facts (`natRole`, the combo fields): a port that negotiates its own rate must not grow a
  `speedMbps: null` line, and a board must not grow one on every port in the catalogue.
* `fromJSON()` restores it beside `duplex`, so `show interfaces` says `100Mb/s (forced)`, running-config still prints
  `speed 100`, and the link itself runs at 100 after the reload - the value the engine uses, not just a field.

Evidence: `test/port-roundtrip.test.js` gained two sections, 32 checks total. The sweep now **configures** first:
one port of every model with a speed ladder is forced to its lowest supported rate (1,902 of 2,038 models), saved,
reloaded, and every field of every port compared. Then the specific case: the saved document carries the rate, the
reloaded port still has it, `show interfaces`, and running-config both still say so, the cable between two 1 Gbps
ports runs at 100 before *and* after the reload, `speed auto` clears it with no stale rate left in the file, a
virgin port's document still contains no `speedMbps` at all, and save -> load -> save is byte-identical.

Reverting `engine/device.js` fails 5 of the 32, naming the models whose rate was lost.

docs/ARCHITECTURE.md: `speedMbps` added to the lost-on-reload table, and the reason a virgin-lab sweep cannot see a
setting, with the two conventions (unset fields are not written; a cache the file drops is checked by behaviour -
the reloaded port must still classify into the same VLAN). docs/CLI.md: the forced rate survives a save.

Suite: 204 suites, 7,869 assertions, 0 failed. Syntax: 272 files, OK.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-11 00:47:15 +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!1406
No description provided.