fix(chat): retarde le fallback custom→TUI tant que le catalogue agents/profiles est stale (#149)

Cause racine restante après le fix de la course au premier chargement : le
garde-fou de LayoutGrid retombait sur `tui` dès que agents/profiles semblaient
indisponibles, y compris quand le cache était simplement stale (refresh en
cours), écrasant silencieusement la préférence custom. Le fallback n'agit
désormais qu'une fois le catalogue confirmé à jour.

QA verte : LayoutGrid.chat.test.tsx (7 tests), src/features/layout (16
fichiers, 130 tests), cas ciblé "stale catalog refresh".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-05 14:06:18 +02:00
parent fa518415c6
commit 61055779c4
2 changed files with 121 additions and 17 deletions

View File

@ -254,6 +254,65 @@ describe("LayoutGrid custom agent CLI (#147)", () => {
expect(window.localStorage.getItem(`idea.agent-cell-mode.p1.${leafId}`)).toBe("custom");
});
it("keeps restored custom CLI mode until a stale catalog refresh sees the agent/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]);
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");
let staleCatalog = true;
const originalListAgents = agent.listAgents.bind(agent);
const originalListProfiles = profileGateway.listProfiles.bind(profileGateway);
vi.spyOn(agent, "listAgents").mockImplementation(async (projectId) => {
if (staleCatalog) return [];
return originalListAgents(projectId);
});
vi.spyOn(profileGateway, "listProfiles").mockImplementation(async () => {
if (staleCatalog) return [];
return originalListProfiles();
});
renderGrid({
layout,
agent,
profile: profileGateway,
terminal,
system,
} as unknown as Gateways);
await waitFor(() => expect(screen.getByTestId("layout-leaf")).toBeTruthy());
await waitFor(() => expect(agent.listAgents).toHaveBeenCalled());
expect(window.localStorage.getItem(`idea.agent-cell-mode.p1.${leafId}`)).toBe("custom");
expect(screen.queryByTestId("custom-agent-chat-view")).toBeNull();
expect(screen.getByTestId("terminal-view")).toBeTruthy();
staleCatalog = false;
system.emit({
type: "agentProfileChanged",
agentId: created.id,
profileId: structuredProfile.id,
});
await waitFor(() =>
expect(screen.getByTestId("custom-agent-chat-view")).toBeTruthy(),
);
expect(window.localStorage.getItem(`idea.agent-cell-mode.p1.${leafId}`)).toBe("custom");
});
it("falls back to native TUI once the catalog confirms the pinned profile is incompatible", async () => {
const layout = new MockLayoutGateway();
const agent = new MockAgentGateway();