Skip to main content
Glama
slash_command_routing_test.go2.68 kB
package tui import ( "testing" ) func TestSlashCommandRoutingLogic(t *testing.T) { tests := []struct { name string terminalFocused bool hasCurrentSession bool expectedInterceptSlash bool description string }{ { name: "Terminal not focused", terminalFocused: false, hasCurrentSession: true, expectedInterceptSlash: true, description: "When terminal is not focused, slash should always open Brummer commands", }, { name: "No current session", terminalFocused: true, hasCurrentSession: false, expectedInterceptSlash: true, description: "When no session exists, slash should open Brummer commands", }, { name: "Terminal focused with session", terminalFocused: true, hasCurrentSession: true, expectedInterceptSlash: false, // This will depend on cursor position description: "When terminal focused with session, behavior depends on cursor position", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // Create PTY view for testing the basic logic view := &AICoderPTYView{ terminalFocused: tt.terminalFocused, currentSession: nil, // Will be set based on hasCurrentSession } // The specific cursor position logic is tested separately // since it requires a real PTY session with terminal state // Test the basic routing logic without cursor position shouldIntercept := view.ShouldInterceptSlashCommand() if tt.hasCurrentSession { // When there's no session, it should always intercept if view.currentSession == nil && !shouldIntercept { t.Errorf("%s: expected shouldIntercept=true when no session", tt.description) } } else { // When there's no session, it should always intercept if !shouldIntercept { t.Errorf("%s: expected shouldIntercept=true when no session", tt.description) } } }) } } func TestSlashCommandContextLogic(t *testing.T) { // Test the core decision logic view := &AICoderPTYView{} // Case 1: Terminal not focused -> always intercept view.terminalFocused = false view.currentSession = nil if !view.ShouldInterceptSlashCommand() { t.Error("Should intercept when terminal not focused") } // Case 2: No current session -> always intercept view.terminalFocused = true view.currentSession = nil if !view.ShouldInterceptSlashCommand() { t.Error("Should intercept when no current session") } // Case 3: With session and focused -> depends on cursor position // (This would require a mock session to test fully) }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/standardbeagle/brummer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server