fix(ai): discard proposals when section context changes

This commit is contained in:
cesnimda
2026-11-03 15:24:55 +01:00
parent e5a979386d
commit a88310481f
10 changed files with 83 additions and 3 deletions
@@ -176,6 +176,8 @@ test.each([
["text", { text: "Changed career facts" }],
["target", { targetId: "experience:job-2" }],
["document language", { documentLanguage: "en" }],
["context", { context: "Different recorded job requirements" }],
["section name", { sectionName: "Different section purpose" }],
] as const)("a changed %s invalidates a pending suggestion", async (_source, updates) => {
const request = deferred<Proposal>();
const { onAccept, rerenderAssistant } = renderAssistant({ onGenerate: jest.fn().mockReturnValue(request.promise) });
@@ -188,12 +190,16 @@ test.each([
expect(onAccept).not.toHaveBeenCalled();
});
test("source changes remove an existing review before it can be accepted", async () => {
test.each([
["text", { text: "Changed career facts" }],
["context", { context: "Different recorded job requirements" }],
["section name", { sectionName: "Different section purpose" }],
] as const)("changed %s removes an existing review before it can be accepted", async (_source, updates) => {
const { onAccept, rerenderAssistant } = renderAssistant();
fireEvent.click(screen.getByRole("button", { name: "AI suggestions" }));
fireEvent.click(screen.getByRole("button", { name: "Suggest" }));
expect(await screen.findByDisplayValue("Proposed wording")).toBeInTheDocument();
rerenderAssistant({ text: "Changed career facts" });
rerenderAssistant(updates);
expect(screen.queryByDisplayValue("Proposed wording")).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Apply" })).not.toBeInTheDocument();
expect(onAccept).not.toHaveBeenCalled();
@@ -42,7 +42,7 @@ export default function AiSectionAssistant({ sectionName, text, context, documen
setBusy(false);
setApplying(false);
return () => { requestId.current += 1; };
}, [text, targetId, normalizedLanguage, targetLanguage, canUseAi]);
}, [text, targetId, context, sectionName, normalizedLanguage, targetLanguage, canUseAi]);
const discard = () => {
requestId.current += 1;