Fix e2e daemon isolation and fast model defaults

This commit is contained in:
Mohamed Boudra
2026-01-20 13:36:06 +07:00
parent facd99ab13
commit 513138ac13
8 changed files with 144 additions and 23 deletions
+1 -1
View File
@@ -217,7 +217,7 @@ function AppWithSidebar({ children }: { children: ReactNode }) {
// useLocalSearchParams doesn't update when navigating between same-pattern routes
const selectedAgentKey = useMemo(() => {
// Match /agent/[serverId]/[agentId] pattern
const match = pathname.match(/^\/agent\/([^/]+)\/([^/]+)$/);
const match = pathname.match(/^\/agent\/([^/]+)\/([^/]+)\/?$/);
if (match) {
const [, serverId, agentId] = match;
return `${serverId}:${agentId}`;
@@ -624,7 +624,7 @@ function AgentScreenContent({
)}
</Pressable>
<View ref={menuButtonRef} collapsable={false}>
<Pressable onPress={handleOpenMenu} style={styles.menuButton}>
<Pressable testID="agent-overflow-menu" onPress={handleOpenMenu} style={styles.menuButton}>
<MoreVertical size={16} color={theme.colors.foregroundMuted} />
</Pressable>
</View>
@@ -12,6 +12,7 @@ import { StyleSheet, UnistylesRuntime, useUnistyles } from "react-native-unistyl
import { Plus, Settings } from "lucide-react-native";
import { router } from "expo-router";
import { usePanelStore } from "@/stores/panel-store";
import { useSessionStore } from "@/stores/session-store";
import { AgentList } from "./agent-list";
import { useAggregatedAgents } from "@/hooks/use-aggregated-agents";
import { useSidebarAnimation } from "@/contexts/sidebar-animation-context";
@@ -24,6 +25,30 @@ interface SlidingSidebarProps {
selectedAgentId?: string;
}
function buildCreateAgentRouteFromSelectedAgentKey(selectedAgentKey?: string) {
if (!selectedAgentKey) {
return { pathname: "/" as const, params: {} as Record<string, string> };
}
const [serverId, agentId] = selectedAgentKey.split(":", 2);
if (!serverId || !agentId) {
return { pathname: "/" as const, params: {} as Record<string, string> };
}
const state = useSessionStore.getState();
const agent = state.sessions[serverId]?.agents.get(agentId);
if (!agent) {
return { pathname: "/" as const, params: {} as Record<string, string> };
}
const params: Record<string, string> = { serverId: agent.serverId };
if (agent.provider) params.provider = agent.provider;
if (agent.currentModeId) params.modeId = agent.currentModeId;
if (agent.model) params.model = agent.model;
if (agent.cwd) params.workingDir = agent.cwd;
return { pathname: "/" as const, params };
}
export function SlidingSidebar({ selectedAgentId }: SlidingSidebarProps) {
const { theme } = useUnistyles();
const insets = useSafeAreaInsets();
@@ -81,17 +106,20 @@ export function SlidingSidebar({ selectedAgentId }: SlidingSidebarProps) {
closeToAgent();
}, [closeToAgent]);
const handleCreateAgent = useCallback(() => {
router.push(buildCreateAgentRouteFromSelectedAgentKey(selectedAgentId));
}, [selectedAgentId]);
// Mobile: close sidebar and navigate
const handleCreateAgentMobile = useCallback(() => {
closeToAgent();
router.push("/");
}, [closeToAgent]);
handleCreateAgent();
}, [closeToAgent, handleCreateAgent]);
// Desktop: just navigate, don't close
const handleCreateAgentDesktop = useCallback(() => {
router.push("/");
}, []);
handleCreateAgent();
}, [handleCreateAgent]);
// Mobile: close sidebar and navigate
const handleSettingsMobile = useCallback(() => {
@@ -211,6 +239,7 @@ export function SlidingSidebar({ selectedAgentId }: SlidingSidebarProps) {
styles.newAgentButton,
hovered && styles.newAgentButtonHovered,
]}
testID="sidebar-new-agent"
onPress={handleCreateAgentMobile}
>
<Plus size={18} color={theme.colors.foreground} />
@@ -262,6 +291,7 @@ export function SlidingSidebar({ selectedAgentId }: SlidingSidebarProps) {
styles.newAgentButton,
hovered && styles.newAgentButtonHovered,
]}
testID="sidebar-new-agent"
onPress={handleCreateAgentDesktop}
>
<Plus size={18} color={theme.colors.foreground} />
@@ -163,8 +163,14 @@ function resolveFormState(
} else {
result.model = "";
}
} else if (providerPrefs?.model && isValidModel(providerPrefs.model)) {
result.model = providerPrefs.model;
} else if (typeof providerPrefs?.model === "string" && providerPrefs.model.length > 0) {
// If models haven't loaded yet, optimistically apply the stored preference.
// We'll validate once models load and clear it if it isn't available.
if (!availableModels || isValidModel(providerPrefs.model)) {
result.model = providerPrefs.model;
} else {
result.model = "";
}
} else {
result.model = "";
}