Repository navigation
pkg/streamer, pkg/terminal, pkg/device/ros: handle cursor-up and deliver trailing prompt on EOF - #364
AdamMagued wants to merge 3 commits into
Conversation
…ling prompt delivery
| module github.com/annetutil/gnetcli | ||
|
|
||
| go 1.25.0 | ||
| go 1.23 |
| // line may be like this "\r\n\r\r\r\r[admin@mk-rb3011-test] > (~1000 space) \r[admin@mk-rb3011-test] > " | ||
| hiddenPrompt = `(?P<hidden>\[\S+@\S+\]\s{1,2}(\/[\/\w\s-]+)?(<SAFE)?>\s+)?` | ||
| visiblePrompt = `\[(?P<login>\S+)@(?P<hostname>\S+)\]\s{1,2}(?P<cfg_path>\/[\/\w\s-]+)?(<(?P<safe_mode>SAFE))?> $` | ||
| visiblePrompt = `\[(?P<login>\S+)@(?P<hostname>[^\]]+)\]\s+(?P<cfg_path>\/[\/\w\s-]+)?(<(?P<safe_mode>SAFE))?>[^\n]*$` |
There was a problem hiding this comment.
The new >[^\n]*$ suffix also matches an incomplete command echo, not just an idle prompt. For example, if the echo arrives in two chunks:
Chunk 1: \r\r[admin@router] > /ip service exp
Chunk 2: ort\r\n
The first chunk is now recognized as a prompt. GenericExecute consumes the matched text and preserves only the bytes before it, losing the command prefix. When the second chunk arrives, the full echo can no longer be reconstructed, and
execution fails with echo read error.
…se echo matches Signed-off-by: AdamMagued <adamismailmageud@gmail.com>
|
@gescheit Restored go 1.25.0 in go.mod and refined the RouterOS prompt regex to prevent false matches on split command echoes. All unit tests pass cleanly. |
| // line may be like this "\r\n\r\r\r\r[admin@mk-rb3011-test] > (~1000 space) \r[admin@mk-rb3011-test] > " | ||
| hiddenPrompt = `(?P<hidden>\[\S+@\S+\]\s{1,2}(\/[\/\w\s-]+)?(<SAFE)?>\s+)?` | ||
| visiblePrompt = `\[(?P<login>\S+)@(?P<hostname>\S+)\]\s{1,2}(?P<cfg_path>\/[\/\w\s-]+)?(<(?P<safe_mode>SAFE))?> $` | ||
| visiblePrompt = `\[(?P<login>\S+)@(?P<hostname>[^\]]+)\]\s+(?P<cfg_path>\/[\/\w\s-]+)?(<(?P<safe_mode>SAFE))?> *$` |
There was a problem hiding this comment.
The new hostname pattern [^\]]+ also matches CR/LF, so it can consume command output together with the actual prompt.
For example, after the command echo:
[alice@example.net\r\n[admin@router] >
The entire buffer is recognized as a prompt. I reproduced this with the same mock-SSH test on both revisions: base returns "[alice@example.net\n", while this PR returns an empty output with status 0 and no error.
Please exclude CR/LF from the hostname character class and add a command-execution regression test that verifies the output is preserved.
There was a problem hiding this comment.
Excluded \r and \n from the hostname character class ((?P[^\]\r\n]+)) and added unit and mock-SSH regression tests verifying that bracketed command output preceding the prompt is preserved.
| } | ||
| } | ||
| if !ok { | ||
| if cfg.regExpr != nil { |
There was a problem hiding this comment.
Is this additional EOF match necessary? GenericReadX already checks the expression against buffer before entering the select. When the receive returns ok == false, no new bytes are appended, so matching the same buffer again cannot produce a different result for the standard expressions.
I tested both a prompt already in inBuffer and a prompt queued in the channel before it closes; both scenarios pass on base as well as on this PR.
Could we remove this branch, or add a regression test that fails on base and demonstrates the scenario it fixes?
There was a problem hiding this comment.
Removed the redundant EOF match block in GenericReadX.
…F match Exclude carriage return and line feed from the visiblePrompt hostname regex to prevent consuming command output preceding the prompt. Add unit and mock-SSH regression tests ensuring bracketed output lines are preserved. Remove redundant EOF match block in GenericReadX. Signed-off-by: Adam Magued <adamismailmageud@gmail.com>
|
@gescheit Updated with the requested fixes:
|
Fixes issue #322 where RouterOS tool traceroute and ping fail with generic_error when a hop does not answer due to unhandled cursor-up/down sequences, discarded trailing prompt on EOF, early error check in chanReader, and narrow search window.