fix(chat): stabilise le mode CLI custom contre le refetch stale agents/profiles (#149)
Le fallback custom→TUI se redéclenchait après le premier chargement dès que refreshProfiles() renvoyait un instant un profil pinné sans structuredAdapter (refetch en vol), coupant la CLI custom ~0.5s après son ouverture. Introduit un binding "trusted" (agent+profil validés) qui reste valide tant qu'aucun changement légitime de profil n'est observé via agentProfileChanged, et ne retombe en TUI que sur perte réelle du CLI custom. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@ -54,7 +54,7 @@ import {
|
||||
} from "@/adapters/mock";
|
||||
import { DIProvider } from "@/app/di";
|
||||
import { leaves } from "./layout";
|
||||
import { LayoutGrid } from "./LayoutGrid";
|
||||
import { LayoutGrid, shouldFallbackCustomCliMode } from "./LayoutGrid";
|
||||
|
||||
const structuredProfile: AgentProfile = {
|
||||
id: "mock-structured",
|
||||
@ -366,4 +366,66 @@ describe("LayoutGrid custom agent CLI (#147)", () => {
|
||||
expect(screen.getByTestId("terminal-view")).toBeTruthy();
|
||||
expect(screen.queryByTestId("custom-agent-chat-view")).toBeNull();
|
||||
});
|
||||
|
||||
it("does not downgrade a validated custom CLI on a contradictory refetch without a profile-change event (#149)", () => {
|
||||
expect(
|
||||
shouldFallbackCustomCliMode({
|
||||
agentsLoaded: true,
|
||||
profilesLoaded: true,
|
||||
cellMode: "custom",
|
||||
hasPinnedAgent: true,
|
||||
hasPinnedProfile: true,
|
||||
customCliAvailable: false,
|
||||
effectiveCustomCliAvailable: true,
|
||||
hasTrustedCustomCli: true,
|
||||
hasLegitProfileChange: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("falls back to native TUI after a legitimate profile-change event downgrades the profile (#149)", async () => {
|
||||
const layout = new MockLayoutGateway();
|
||||
const agent = new MockAgentGateway();
|
||||
const profileGateway = new MockProfileGateway();
|
||||
const terminal = new MockTerminalGateway();
|
||||
const system = new MockSystemGateway();
|
||||
await profileGateway.configureProfiles([structuredProfile, ptyProfile]);
|
||||
const created = await agent.createAgent("p1", {
|
||||
name: "Worker",
|
||||
profileId: structuredProfile.id,
|
||||
});
|
||||
const tree = await layout.loadLayout("p1");
|
||||
const leafId = leaves(tree)[0].id;
|
||||
await layout.mutateLayout("p1", {
|
||||
type: "setCellAgent",
|
||||
target: leafId,
|
||||
agent: created.id,
|
||||
});
|
||||
window.localStorage.setItem(`idea.agent-cell-mode.p1.${leafId}`, "custom");
|
||||
|
||||
renderGrid({
|
||||
layout,
|
||||
agent,
|
||||
profile: profileGateway,
|
||||
terminal,
|
||||
system,
|
||||
} as unknown as Gateways);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId("custom-agent-chat-view")).toBeTruthy(),
|
||||
);
|
||||
|
||||
await agent.changeAgentProfile("p1", created.id, ptyProfile.id, 24, 80);
|
||||
system.emit({
|
||||
type: "agentProfileChanged",
|
||||
agentId: created.id,
|
||||
profileId: ptyProfile.id,
|
||||
});
|
||||
|
||||
await waitFor(() =>
|
||||
expect(window.localStorage.getItem(`idea.agent-cell-mode.p1.${leafId}`)).toBe("tui"),
|
||||
);
|
||||
expect(screen.getByTestId("terminal-view")).toBeTruthy();
|
||||
expect(screen.queryByTestId("custom-agent-chat-view")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user