@@ -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