Skip to content

Commit 5c41195

Browse files
committed
fix: Apply end_context when end/exit is a sequence step
In scenario mode, end and exit were blocked from applying their context effect because inScenario was still true after the sequence step advanced. Now explicitly apply handleExitEnd when the sequence step was end or exit.
1 parent daeffd0 commit 5c41195

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

ssh_server/handlers/ciscohandlers.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ func handleShellInput(t *term.Terminal, userInput string, fd *fakedevices.FakeDe
8080
return true
8181
}
8282

83-
// Apply context switch if the input matches a context_search key.
84-
// Uses starts-with-N-words semantics so "interface Gi0/0/2" matches key "interface".
85-
// In scenario mode (active sequence), context switches only fire when the sequence
86-
// step was just handled — enforcing strict command ordering.
8783
inScenario := seqIdx != nil && *seqIdx < len(sequence)
84+
85+
// Apply context switch if the input matches a context_search key.
86+
// In scenario mode, only fires when the sequence step was just handled.
8887
if !inScenario || sequenceHandled {
8988
if matchedCtx, ok := matchContextKey(userInput, fd.ContextSearch); ok {
9089
t.SetPrompt(devicePrompt(fd, fd.ContextSearch[matchedCtx]))
@@ -93,19 +92,23 @@ func handleShellInput(t *term.Terminal, userInput string, fd *fakedevices.FakeDe
9392
}
9493
}
9594

96-
if sequenceHandled {
97-
return false
95+
// exit/end: always apply when sequence step matched; in non-scenario mode always apply;
96+
// in scenario mode "end" is blocked unless it was the current step.
97+
if userInput == "exit" || userInput == "end" {
98+
if sequenceHandled || !inScenario || userInput == "exit" {
99+
return handleExitEnd(t, userInput, fd, contextState)
100+
}
98101
}
99102

100-
if userInput == "exit" {
101-
return handleExitEnd(t, userInput, fd, contextState)
103+
if sequenceHandled {
104+
return false
102105
}
103106

104-
// In scenario mode, "end" is blocked unless it was the current sequence step
105-
if userInput == "end" && !inScenario {
106-
return handleExitEnd(t, userInput, fd, contextState)
107-
}
107+
return handleStateCommands(t, userInput, fd, contextState)
108+
}
108109

110+
// handleStateCommands handles reset state, hostname changes, and supported command dispatch.
111+
func handleStateCommands(t *term.Terminal, userInput string, fd *fakedevices.FakeDevice, contextState *string) bool {
109112
if userInput == "reset state" {
110113
t.Write(append([]byte("Resetting State..."), '\n'))
111114
*contextState = fd.ContextSearch["base"]

0 commit comments

Comments
 (0)