Przeglądaj źródła

fix(tui): refresh moved tab metadata (#42696)

Kit Langton 1 dzień temu
rodzic
commit
98f5e86122

+ 6 - 0
packages/tui/src/context/session-tabs.tsx

@@ -247,6 +247,12 @@ export const { use: useSessionTabs, provider: SessionTabsProvider } = createSimp
     onCleanup(event.on("session.execution.succeeded", (evt) => markUnread(evt.data.sessionID, "activity")))
     onCleanup(event.on("session.execution.interrupted", (evt) => markUnread(evt.data.sessionID, "activity")))
     onCleanup(event.on("session.execution.failed", (evt) => markUnread(evt.data.sessionID, "error")))
+    onCleanup(
+      event.on("session.moved", (evt) => {
+        if (!enabled() || !state().tabs.some((tab) => tab.sessionID === root(evt.data.sessionID))) return
+        void Promise.allSettled([data.location.syncInfo(evt.data.location), data.location.vcs.sync(evt.data.location)])
+      }),
+    )
     onCleanup(
       event.on("session.inbox.enqueued", (evt) => {
         if (!enabled() || evt.data.item.type !== "user") return

+ 26 - 0
packages/tui/test/context/session-tabs.test.tsx

@@ -197,6 +197,32 @@ test("loads VCS metadata for each persisted tab location", async () => {
   }
 })
 
+test("loads location metadata when an open session moves", async () => {
+  const destination = `${directory}/moved-worktree`
+  const setup = await renderSessionTabs("first")
+
+  try {
+    await wait(() => setup.locations.includes(directory) && setup.vcsLocations.includes(directory))
+    setup.emit({
+      id: "evt_moved",
+      created: 1,
+      type: "session.moved",
+      durable: { aggregateID: "first", seq: 1, version: 1 },
+      data: {
+        sessionID: "first",
+        location: { directory: destination },
+        projectID: "project",
+      },
+    })
+
+    await wait(() => setup.data.session.get("first")?.location.directory === destination)
+    await wait(() => setup.locations.includes(destination))
+    await wait(() => setup.vcsLocations.includes(destination))
+  } finally {
+    await setup.destroy()
+  }
+})
+
 test("stores session tabs for the current working directory by default", async () => {
   const setup = await renderSessionTabs("first")