show running-config is now a config you can paste back (#1230) #1231

Merged
jaylouisw merged 1 commit from fix/running-config-pasteable into main 2026-11-09 16:31:43 +00:00
Owner

show running-config is now a config you can paste back

Fixes #1230.

Pasting a running-config into a fresh device reported an error on almost every line, and the lines that
were accepted applied themselves to the wrong port: an address meant for Gi0/0/0 and a shutdown
meant for Gi0/0/1 both landed on the first interface in the file.

% Unrecognized config command: ! PacketForge running-config
% Unrecognized interface command: interface Gi0/0/0
% Unrecognized interface command: ip route 0.0.0.0 0.0.0.0 10.1.2.1

interface Gi0
  ip address 10.1.2.3 255.255.255.0     <- belonged to Gi0/0/0
  shutdown                              <- belonged to Gi0/0/1

Three causes, all in engine/cli.js

The printer never emitted exit. Interface blocks came back to back, so a reader never left
interface mode; everything after the first block — global commands included — was parsed as an
interface command. Each block now closes with exit.

The printer's own header was rejected. ! PacketForge running-config came back as
% Unrecognized config command. Comment lines (! and #) are now ignored before dispatch, in every
mode.

interface <name> inside interface mode was an error. It is a mode switch in every real CLI, and
the config-mode handler already knows how to open an interface (dot1q subinterfaces included), so it is
reused. A line that is not an interface command now falls through to the config-mode dispatcher before
being refused — which is what makes a config copied out before this fix still replayable. Those
backups are block-after-block with no exit, so accepting only the corrected shape would have
invalidated every config anyone had already copied.

A fourth, found by the sweep

The catalogue sweep turned up interfaces whose names contain spaces — Ubiquiti's Port 1, SFP+ 1.
interface Port 1 was read as an interface called Port and refused, so those devices could never
replay their own config. An interface name is now the whole rest of the line (tokens.slice(1).join(' '),
and the same for no interface).

Evidence

New test/config-roundtrip.test.js, 22 checks:

  • a config pasted from show running-config — header comment included — is accepted with zero
    rejections and reproduces itself byte for byte;
  • the address is on Gi0/0/0 and the shutdown on Gi0/0/1, and nothing landed on the parent;
  • the same config with the exit lines stripped (the pre-fix shape) also replays cleanly, global
    section included;
  • comments are ignored at the exec, config and interface prompts; interface Gi0/0/1 inside interface
    mode switches instead of erroring, and the following shutdown applies to the new interface; an
    interface that does not exist is still refused;
  • a sweep over the catalogue — 1,866 models — prints each device's own running-config and reads it
    back
    : no rejections, and identical output.

That sweep is the test that found the space-in-name bug, which is why it is kept rather than replaced
with a fixture.

docs/CLI.md documents the invariant and what makes it hold.

Suite: 132 suites, 5,757 assertions, 0 failed.

`show running-config` is now a config you can paste back Fixes #1230. Pasting a running-config into a fresh device reported an error on almost every line, and the lines that *were* accepted applied themselves to the wrong port: an address meant for `Gi0/0/0` and a `shutdown` meant for `Gi0/0/1` both landed on the first interface in the file. ``` % Unrecognized config command: ! PacketForge running-config % Unrecognized interface command: interface Gi0/0/0 % Unrecognized interface command: ip route 0.0.0.0 0.0.0.0 10.1.2.1 interface Gi0 ip address 10.1.2.3 255.255.255.0 <- belonged to Gi0/0/0 shutdown <- belonged to Gi0/0/1 ``` ## Three causes, all in `engine/cli.js` **The printer never emitted `exit`.** Interface blocks came back to back, so a reader never left interface mode; everything after the first block — global commands included — was parsed as an interface command. Each block now closes with `exit`. **The printer's own header was rejected.** `! PacketForge running-config` came back as `% Unrecognized config command`. Comment lines (`!` and `#`) are now ignored before dispatch, in every mode. **`interface <name>` inside interface mode was an error.** It is a mode switch in every real CLI, and the config-mode handler already knows how to open an interface (dot1q subinterfaces included), so it is reused. A line that is not an interface command now falls through to the config-mode dispatcher before being refused — which is what makes a config copied out **before** this fix still replayable. Those backups are block-after-block with no `exit`, so accepting only the corrected shape would have invalidated every config anyone had already copied. ## A fourth, found by the sweep The catalogue sweep turned up interfaces whose names contain spaces — Ubiquiti's `Port 1`, `SFP+ 1`. `interface Port 1` was read as an interface called `Port` and refused, so those devices could never replay their own config. An interface name is now the whole rest of the line (`tokens.slice(1).join(' ')`, and the same for `no interface`). ## Evidence New `test/config-roundtrip.test.js`, 22 checks: * a config pasted from `show running-config` — header comment included — is accepted with **zero** rejections and reproduces itself byte for byte; * the address is on `Gi0/0/0` and the shutdown on `Gi0/0/1`, and nothing landed on the parent; * the same config with the `exit` lines stripped (the pre-fix shape) also replays cleanly, global section included; * comments are ignored at the exec, config and interface prompts; `interface Gi0/0/1` inside interface mode switches instead of erroring, and the following `shutdown` applies to the new interface; an interface that does not exist is still refused; * **a sweep over the catalogue — 1,866 models — prints each device's own running-config and reads it back**: no rejections, and identical output. That sweep is the test that found the space-in-name bug, which is why it is kept rather than replaced with a fixture. `docs/CLI.md` documents the invariant and what makes it hold. Suite: 132 suites, 5,757 assertions, 0 failed.
show running-config is now a config you can paste back
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 18) (pull_request) Successful in 1m39s
CI / Test (Node 20) (pull_request) Successful in 1m37s
CI / Server smoke test (pull_request) Successful in 34s
CI / Docker build (pull_request) Successful in 42s
CI / Test (Node 22) (pull_request) Successful in 1m31s
e3d113da70
Fixes #1230.

Pasting a running-config into a fresh device reported an error on almost every line, and the lines that
*were* accepted applied themselves to the wrong port: an address meant for `Gi0/0/0` and a `shutdown`
meant for `Gi0/0/1` both landed on the first interface in the file.

```
% Unrecognized config command: ! PacketForge running-config
% Unrecognized interface command: interface Gi0/0/0
% Unrecognized interface command: ip route 0.0.0.0 0.0.0.0 10.1.2.1

interface Gi0
  ip address 10.1.2.3 255.255.255.0     <- belonged to Gi0/0/0
  shutdown                              <- belonged to Gi0/0/1
```

## Three causes, all in `engine/cli.js`

**The printer never emitted `exit`.** Interface blocks came back to back, so a reader never left
interface mode; everything after the first block — global commands included — was parsed as an
interface command. Each block now closes with `exit`.

**The printer's own header was rejected.** `! PacketForge running-config` came back as
`% Unrecognized config command`. Comment lines (`!` and `#`) are now ignored before dispatch, in every
mode.

**`interface <name>` inside interface mode was an error.** It is a mode switch in every real CLI, and
the config-mode handler already knows how to open an interface (dot1q subinterfaces included), so it is
reused. A line that is not an interface command now falls through to the config-mode dispatcher before
being refused — which is what makes a config copied out **before** this fix still replayable. Those
backups are block-after-block with no `exit`, so accepting only the corrected shape would have
invalidated every config anyone had already copied.

## A fourth, found by the sweep

The catalogue sweep turned up interfaces whose names contain spaces — Ubiquiti's `Port 1`, `SFP+ 1`.
`interface Port 1` was read as an interface called `Port` and refused, so those devices could never
replay their own config. An interface name is now the whole rest of the line (`tokens.slice(1).join(' ')`,
and the same for `no interface`).

## Evidence

New `test/config-roundtrip.test.js`, 22 checks:

* a config pasted from `show running-config` — header comment included — is accepted with **zero**
  rejections and reproduces itself byte for byte;
* the address is on `Gi0/0/0` and the shutdown on `Gi0/0/1`, and nothing landed on the parent;
* the same config with the `exit` lines stripped (the pre-fix shape) also replays cleanly, global
  section included;
* comments are ignored at the exec, config and interface prompts; `interface Gi0/0/1` inside interface
  mode switches instead of erroring, and the following `shutdown` applies to the new interface; an
  interface that does not exist is still refused;
* **a sweep over the catalogue — 1,866 models — prints each device's own running-config and reads it
  back**: no rejections, and identical output.

That sweep is the test that found the space-in-name bug, which is why it is kept rather than replaced
with a fixture.

`docs/CLI.md` documents the invariant and what makes it hold.

Suite: 132 suites, 5,757 assertions, 0 failed.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-09 16:31:39 +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!1231
No description provided.