Repository navigation
Closed
Closed
Copy link
Labels
vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/web
Steps to reproduce
- Open a pull request review guide and visit a stop with a code excerpt.
- Push a commit that changes the code shown by that stop.
- Rewrite the review guide for the new push.
- Open the rewritten guide at the stop for the same file.
- Open the Code tab and refresh the pull request.
- Return to the guide.
Expected behavior
The rewritten guide shows excerpts from the new push, including after the diff refreshes.
Actual behavior
The guide can keep showing the earlier code even after the Code tab has received the new diff.
Impact
Minor bug or occasional failure. Reviewers who rewrite a guide after a push can read outdated excerpts under the new guide for files already present in the diff cache.
Version or commit
main at 959f422d45. The cause is at apps/web/src/components/pullRequest/guide/useGuideDiffFiles.ts:52.
Environment
Linux x64, the repository's own tests.
Logs or stack traces
AssertionError: expected [ [ 'wanted.ts', 'OLD_HEAD\n' ] ] to deeply equal [ [ 'wanted.ts', 'NEW_HEAD\n' ] ]Automated repro
Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.
diff --git a/apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx b/apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx
index 9780ac0422..920a8c582c 100644
--- a/apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx
+++ b/apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx
@@ -16,11 +16,11 @@ vi.mock("~/state/pullRequests", () => ({
import { useGuideDiffFiles } from "./useGuideDiffFiles";
-function Probe({ wantedPaths }: { wantedPaths: string[] }) {
+function Probe({ wantedPaths, headSha = "new-head" }: { wantedPaths: string[]; headSha?: string }) {
const diff = useGuideDiffFiles({
environmentId: EnvironmentId.make("test"),
reference: { projectId: ProjectId.make("project"), repository: "owner/repo", number: 1 },
- headSha: "new-head",
+ headSha,
wantedPaths,
});
return (
@@ -143,3 +143,28 @@ it("waits for a later cached page that is still refreshing", async () => {
],
});
});
+
+it("replaces cached excerpts when a new guide head receives a refreshed diff", async () => {
+ setup();
+ await using stack = new AsyncDisposableStack();
+ const registry = stack.adopt(AtomRegistry.make(), (value) => value.dispose());
+ const first = Atom.make<AsyncResult.AsyncResult<PullRequestDiffResult>>(
+ AsyncResult.success(page("wanted.ts", "OLD_HEAD", null)),
+ );
+ state.pages.set(null, first);
+ await using screen = await render(
+ <RegistryContext.Provider value={registry}>
+ <Probe wantedPaths={["wanted.ts"]} headSha="old-head" />
+ </RegistryContext.Provider>,
+ );
+ const result = () => JSON.parse(screen.container.querySelector("output")!.textContent!);
+ expect(result().files).toEqual([["wanted.ts", "OLD_HEAD\n"]]);
+
+ await screen.rerender(
+ <RegistryContext.Provider value={registry}>
+ <Probe wantedPaths={["wanted.ts"]} headSha="new-head" />
+ </RegistryContext.Provider>,
+ );
+ await act(() => registry.set(first, AsyncResult.success(page("wanted.ts", "NEW_HEAD", null))));
+ expect(result().files).toEqual([["wanted.ts", "NEW_HEAD\n"]]);
+});cd apps/web && pnpm exec vp test run src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsxWorkaround
No response
Metadata
Metadata
Assignees
Labels
vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
Activity