fix(layout): auto-réparer l'onglet actif

stale

Le backend renvoie l'id actif autoritaire et le
    frontend l'adopte pour éviter de rejouer un layout
    disparu après overwrite externe.

Co-Authored-By: Claude Opus 4.8
    <noreply@anthropic.com>
This commit is contained in:
2026-06-25 16:23:40 +02:00
parent 137620daa3
commit e916ecd95e
14 changed files with 372 additions and 51 deletions

View File

@ -48,8 +48,8 @@ export class TauriLayoutGateway implements LayoutGateway {
});
}
setActiveLayout(projectId: string, layoutId: string): Promise<void> {
return invoke<void>("set_active_layout", {
setActiveLayout(projectId: string, layoutId: string): Promise<{ activeId: string }> {
return invoke<{ activeId: string }>("set_active_layout", {
request: { projectId, layoutId },
});
}

View File

@ -846,11 +846,17 @@ export class MockLayoutGateway implements LayoutGateway {
return { activeId: ps.activeId };
}
async setActiveLayout(projectId: string, layoutId: string): Promise<void> {
async setActiveLayout(
projectId: string,
layoutId: string,
): Promise<{ activeId: string }> {
const ps = this.getProjectLayouts(projectId);
// Self-heal (I4): only adopt the requested id when it exists; otherwise keep
// the current active id. Either way the returned id is authoritative.
if (ps.layouts.some((l) => l.id === layoutId)) {
ps.activeId = layoutId;
}
return { activeId: ps.activeId };
}
}

View File

@ -117,14 +117,25 @@ describe("MockLayoutGateway", () => {
expect(activeId).toBe(newActive);
});
it("setActiveLayout switches the active layout", async () => {
it("setActiveLayout switches the active layout and returns the authoritative id", async () => {
const gw = new MockLayoutGateway();
const { layoutId } = await gw.createLayout("p1", "Alt");
await gw.setActiveLayout("p1", layoutId);
const result = await gw.setActiveLayout("p1", layoutId);
expect(result.activeId).toBe(layoutId);
const { activeId } = await gw.listLayouts("p1");
expect(activeId).toBe(layoutId);
});
it("setActiveLayout self-heals: a stale id keeps (and returns) the current active id", async () => {
const gw = new MockLayoutGateway();
const { activeId: initial } = await gw.listLayouts("p1");
const result = await gw.setActiveLayout("p1", "ghost-layout-id");
// The requested id does not exist → active id is unchanged and returned.
expect(result.activeId).toBe(initial);
const { activeId } = await gw.listLayouts("p1");
expect(activeId).toBe(initial);
});
it("loadLayout with a specific layoutId loads that layout's tree", async () => {
const gw = new MockLayoutGateway();
const { layoutId } = await gw.createLayout("p1", "Named");