mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-17 16:09:36 +00:00
fix(agents): keep worktree tasks refreshing on project VCS events (#2988)
#2979 matched vcsChanged events against the task's cwd. A worktree task's gitdir is <project>/.git/worktrees/<slug>, outside its checkout, so the watcher reports the project root when the agent commits there and the Changes pane stopped refreshing. Worktree tasks now match their project root; local tasks still match only their own checkout. Co-authored-by: panda-student <71381346+panda-student@users.noreply.github.com>
This commit is contained in:
@@ -174,15 +174,18 @@ function TaskSession({ id, docked }: { id: string; docked: boolean }) {
|
||||
}, [id, connected]);
|
||||
// A commit in the task's checkout moves its HEAD: pick it up without waiting for the agent.
|
||||
// The watcher reports every repository under the project, so the main checkout and other
|
||||
// tasks' worktrees would otherwise re-read this task's commits for nothing.
|
||||
const cwd = task?.cwd ?? null;
|
||||
// tasks' worktrees would otherwise re-read this task's changes for nothing. A worktree's
|
||||
// gitdir is `<project>/.git/worktrees/<slug>`, outside the worktree itself: the watcher only
|
||||
// reports the project there, so that is the root its events match.
|
||||
const refreshRoot =
|
||||
task?.isolation === "worktree" ? (task.projectRoot ?? project?.root ?? null) : (task?.cwd ?? null);
|
||||
useEffect(() => {
|
||||
if (!connected) return;
|
||||
return onIdeEvent("vcsChanged", (e) => {
|
||||
if (!cwd || !isSameOrInside(cwd, e.root)) return;
|
||||
if (!refreshRoot || !isSameOrInside(refreshRoot, e.root)) return;
|
||||
scheduleChanges(id);
|
||||
});
|
||||
}, [id, connected, cwd]);
|
||||
}, [id, connected, refreshRoot]);
|
||||
// A kept-alive tab stays mounted behind the shown one: it isn't read there, nor searched.
|
||||
const shown = useEditorShown();
|
||||
useEffect(() => {
|
||||
|
||||
@@ -22,6 +22,7 @@ const backend = vi.hoisted(() => ({
|
||||
changes: [] as AgentChange[],
|
||||
changesCalls: 0,
|
||||
grouped: { uncommitted: [] as AgentChange[], commits: [] as AgentCommit[] },
|
||||
groupedCalls: 0,
|
||||
rolledBack: [] as Array<[string, string[] | null, string | null]>,
|
||||
answers: [] as Array<[string, number, string | null]>,
|
||||
fetched: [] as string[],
|
||||
@@ -59,7 +60,10 @@ vi.mock("@/platform/ipc", async (original) => ({
|
||||
backend.changesCalls += 1;
|
||||
return { status: "ok", data: backend.changes };
|
||||
},
|
||||
agentGroupedChanges: async () => ({ status: "ok", data: backend.grouped }),
|
||||
agentGroupedChanges: async () => {
|
||||
backend.groupedCalls += 1;
|
||||
return { status: "ok", data: backend.grouped };
|
||||
},
|
||||
agentRollbackChanges: async (task: string, paths: string[] | null, view: string | null) => {
|
||||
backend.rolledBack.push([task, paths, view]);
|
||||
return { status: "ok", data: null };
|
||||
@@ -170,6 +174,7 @@ beforeEach(() => {
|
||||
backend.changes = [];
|
||||
backend.changesCalls = 0;
|
||||
backend.grouped = { uncommitted: [], commits: [] };
|
||||
backend.groupedCalls = 0;
|
||||
backend.rolledBack = [];
|
||||
backend.external = [];
|
||||
// The flat list unless a test asks for the grouped view, so counts and selections stay as before.
|
||||
@@ -1407,6 +1412,26 @@ describe("changes refresh", () => {
|
||||
await act(() => vi.advanceTimersByTimeAsync(600));
|
||||
expect(backend.changesCalls).toBe(1);
|
||||
});
|
||||
|
||||
it("re-reads a worktree task's changes on the project's events, where its gitdir lives", async () => {
|
||||
vi.useFakeTimers();
|
||||
useChangesOptions.setState({ groupByCommit: true });
|
||||
useAgents.setState({
|
||||
tasks: new Map([["A", { ...task("A"), isolation: "worktree", cwd: "/worktrees/a", projectRoot: "/project" }]]),
|
||||
});
|
||||
render(<SessionEditor input={input("A")} />);
|
||||
await act(async () => {});
|
||||
backend.groupedCalls = 0;
|
||||
|
||||
act(() => emitLocalIdeEvent({ type: "vcsChanged", root: "/elsewhere" }));
|
||||
await act(() => vi.advanceTimersByTimeAsync(600));
|
||||
expect(backend.groupedCalls).toBe(0);
|
||||
|
||||
// A commit in the worktree writes <project>/.git/worktrees/<slug>, so the event is rooted at the project.
|
||||
act(() => emitLocalIdeEvent({ type: "vcsChanged", root: "/project" }));
|
||||
await act(() => vi.advanceTimersByTimeAsync(600));
|
||||
expect(backend.groupedCalls).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("accept changes", () => {
|
||||
|
||||
Reference in New Issue
Block a user