Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/hunk-session/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ describe("createHunkSessionBridge", () => {
type: "command",
requestId: "reload-1",
command: "reload_session",
input: { sessionId: "session-1", nextInput: { kind: "vcs", staged: false, options: {} } },
input: {
sessionId: "session-1",
nextInput: { kind: "vcs", staged: false, options: {} },
sourcePath: "/repo",
},
});
await bridge.dispatchCommand({
type: "command",
Expand All @@ -133,6 +137,10 @@ describe("createHunkSessionBridge", () => {

expect(handlers.navigateToLocation).toHaveBeenCalledTimes(1);
expect(handlers.reloadSession).toHaveBeenCalledTimes(1);
expect(handlers.reloadSession).toHaveBeenCalledWith(
{ kind: "vcs", staged: false, options: {} },
{ resetApp: false, sourcePath: "/repo" },
);
expect(handlers.removeLiveComment).toHaveBeenCalledTimes(1);
expect(handlers.clearLiveComments).toHaveBeenCalledTimes(1);
});
Expand Down
3 changes: 2 additions & 1 deletion src/hunk-session/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface HunkSessionBridgeHandlers {
HunkSessionServerMessage,
{ command: "reload_session" }
>["input"]["nextInput"],
options?: { sourcePath?: string },
options?: { resetApp?: boolean; sourcePath?: string },
) => Promise<ReloadedSessionResult>;
removeLiveComment: (commentId: string) => RemovedCommentResult;
}
Expand Down Expand Up @@ -68,6 +68,7 @@ export function createHunkSessionBridge(handlers: HunkSessionBridgeHandlers) {
return handlers.navigateToLocation(message.input);
case "reload_session":
return handlers.reloadSession(message.input.nextInput, {
resetApp: false,
sourcePath: message.input.sourcePath,
});
case "remove_comment":
Expand Down
91 changes: 91 additions & 0 deletions src/ui/AppHost.interactions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ function createMockHostClient() {
latestSnapshot = snapshot.state;
},
} as unknown as HunkSessionBrokerClient,
dispatchCommand: async (message: HunkSessionServerMessage) => {
if (!bridge) {
throw new Error("Expected App to register a bridge before running the test command.");
}

return bridge.dispatchCommand(message);
},
getBridge: () => bridge,
getLatestSnapshot: () => latestSnapshot,
navigateToHunk: async (
Expand Down Expand Up @@ -1110,6 +1117,90 @@ describe("App interactions", () => {
}
});

test("session reload preserves live comments while refreshing the file diff", async () => {
const dir = mkdtempSync(join(tmpdir(), "hunk-session-reload-"));
const left = join(dir, "before.ts");
const right = join(dir, "after.ts");
const reviewNote = "Keep this daemon review note";

writeFileSync(left, "export const answer = 41;\n");
writeFileSync(right, "export const answer = 42;\n");

const bootstrap = await loadAppBootstrap({
kind: "diff",
left,
right,
options: {
mode: "split",
},
});
const { dispatchCommand, hostClient } = createMockHostClient();

const setup = await testRender(<AppHost bootstrap={bootstrap} hostClient={hostClient} />, {
width: 220,
height: 20,
});

try {
await flush(setup);

await act(async () => {
await dispatchCommand({
type: "command",
requestId: "comment-1",
command: "comment",
input: {
sessionId: "session-1",
filePath: "after.ts",
side: "new",
line: 1,
summary: reviewNote,
reveal: true,
},
});
});

let frame = await waitForFrame(setup, (currentFrame) => currentFrame.includes(reviewNote));
expect(frame).toContain(reviewNote);

writeFileSync(right, "export const answer = 42;\nexport const added = true;\n");

await act(async () => {
await dispatchCommand({
type: "command",
requestId: "reload-1",
command: "reload_session",
input: {
sessionId: "session-1",
nextInput: {
kind: "diff",
left,
right,
options: {
mode: "split",
},
},
sourcePath: dir,
},
});
});

frame = await waitForFrame(
setup,
(currentFrame) => currentFrame.includes("export const added = true;"),
20,
);

expect(frame).toContain("export const added = true;");
expect(frame).toContain(reviewNote);
} finally {
await act(async () => {
setup.renderer.destroy();
});
rmSync(dir, { force: true, recursive: true });
}
});

test("watch mode reloads the current file diff from disk", async () => {
const dir = mkdtempSync(join(tmpdir(), "hunk-watch-"));
const left = join(dir, "before.ts");
Expand Down
Loading