Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix: preserve reviewed wording after undoing assistant rejections

Amruth Pillaiefbd5691e756
diff --git a/apps/mobile/scripts/assistant-proposals.test.mjs b/apps/mobile/scripts/assistant-proposals.test.mjs
index f573bbcb4..da0a5539a 100644
--- a/apps/mobile/scripts/assistant-proposals.test.mjs
+++ b/apps/mobile/scripts/assistant-proposals.test.mjs
@@ -401,6 +401,7 @@ test("native chat records real successes and explicit history changes, never ref
},
};
const message = { id: "message", role: "assistant", parts: [part] };
+ let receiptMessage = message;
const records = [];
// What the receipts read back returns; TanStack Query resolves a failed refetch with the error and old data.
let receiptRead = async () => ({ data: { messages: [message] }, isError: false });
@@ -470,7 +471,7 @@ test("native chat records real successes and explicit history changes, never ref
"@/routes": { routes: {} },
"@tanstack/react-query": {
useQuery: (options) => {
- const data = { messages: [message], thread: {}, isReadOnly: false };
+ const data = { messages: [receiptMessage], thread: {}, isReadOnly: false };
return {
data: options?.select ? options.select(data) : data,
isFetchedAfterMount: true,
@@ -626,6 +627,10 @@ test("native chat records real successes and explicit history changes, never ref
// New wording counts only once a fresh read of the receipts shows it; a failed read keeps the draft open.
const reworded = part.output.edits[1];
+ handlers.onReject(message, part, [reworded]);
+ handlers = render();
+ handlers.onRestore(message, part, [reworded]);
+ handlers = render();
const wording = shared.withEditedText(reworded, "My wording").after;
const withWording = {
...message,
@@ -640,12 +645,22 @@ test("native chat records real successes and explicit history changes, never ref
await assert.rejects(handlers.onEdit(message, part, reworded, "My wording"), /couldn't be read back/);
receiptRead = async () => ({ data: { messages: [message] }, isError: false });
await assert.rejects(handlers.onEdit(message, part, reworded, "My wording"), /couldn't be read back/);
- receiptRead = async () => ({ data: { messages: [withWording] }, isError: false });
+ receiptRead = async () => {
+ receiptMessage = withWording;
+ return { data: { messages: [withWording] }, isError: false };
+ };
await handlers.onEdit(message, part, reworded, "My wording");
assert.deepEqual(
records.slice(-3),
Array(3).fill([{ id: "conflict", status: "pending", text: "My wording", after: reworded.after }]),
);
+ handlers = render();
+ const reviewed = proposals.toProposals(part, handlers.statuses).find((proposal) => proposal.id === reworded.id);
+ assert.equal(reviewed.after, wording, "Undo rejection must retain the wording confirmed by the server");
+ handlers.onAccept(message, part, [reviewed]);
+ await resumeStore.getState().flush();
+ assert.equal(resumeStore.getState().data.summary.content, wording);
+ assert.equal(documentSaves.at(-1).applications[reworded.id], wording);
// A failed read never confirms, even when the receipts it kept already show that wording.
receiptRead = async () => ({ data: { messages: [withWording] }, isError: true });
await assert.rejects(handlers.onEdit(message, part, reworded, "My wording"), /couldn't be read back/);
diff --git a/apps/mobile/src/features/assistant/chat-view.tsx b/apps/mobile/src/features/assistant/chat-view.tsx
index 6c28b3ffe..3854555fe 100644
--- a/apps/mobile/src/features/assistant/chat-view.tsx
+++ b/apps/mobile/src/features/assistant/chat-view.tsx
@@ -523,8 +523,8 @@ function Conversation(props: ConversationProps) {
(stopped || (lastReply !== undefined && (history.data?.interrupted ?? []).includes(lastReply.id)));
const saidSomething = lastReply?.parts.some((part) => part.type === "text" && part.text.trim() !== "") === true;
const statuses = useMemo(() => {
- const map = new Map<string, Receipt>([
- ...((receipts.data?.messages ?? []) as UIMessage[]).flatMap((message) =>
+ const map = new Map<string, Receipt>(
+ ((receipts.data?.messages ?? []) as UIMessage[]).flatMap((message) =>
message.parts.flatMap((part) =>
isProposeEdits(part)
? toProposals(part, new Map()).map(
@@ -534,8 +534,8 @@ function Conversation(props: ConversationProps) {
: [],
),
),
- ...[...rejections].map(([id, status]) => [id, { status }] as const),
- ]);
+ );
+ for (const [id, status] of rejections) map.set(id, { ...map.get(id), status });
// Only an undecided edit reads as replaced: one accepted or rejected (here or on another device) keeps its outcome.
for (const id of supersededIds.split(" ").filter(Boolean))
if ((map.get(id)?.status ?? "pending") === "pending") map.set(id, { status: "rejected", superseded: true });
diff --git a/apps/web/src/features/assistant/conversation.test.tsx b/apps/web/src/features/assistant/conversation.test.tsx
index 5e884fbad..49c633556 100644
--- a/apps/web/src/features/assistant/conversation.test.tsx
+++ b/apps/web/src/features/assistant/conversation.test.tsx
@@ -625,7 +625,7 @@ it("never accepts tailored or older sets into a resume that isn't the job's copy
}
});
-it("keeps the wording draft and every Accept closed until a fresh read shows the saved wording", async () => {
+it("keeps restored edits and Accept bound to wording confirmed by a fresh read", async () => {
const saved = {
messages: [
proposing({
@@ -657,8 +657,18 @@ it("keeps the wording draft and every Accept closed until a fresh read shows the
return { data, isError: false };
});
mocks.receipts.mockImplementation(() => ({ data, refetch }));
- mocks.record.mockRejectedValueOnce(new Error("offline")).mockResolvedValue({});
- const { accept, rerender } = renderConversation([proposing({ tailoredFor: "application-2" })]);
+ mocks.record
+ .mockResolvedValueOnce({})
+ .mockResolvedValueOnce({})
+ .mockRejectedValueOnce(new Error("offline"))
+ .mockResolvedValue({});
+ const { accept, rerender } = renderConversation([proposing({ tailoredFor: "application-2" })], {
+ stateOf: (proposal) => proposal.status,
+ });
+ fireEvent.click(screen.getByRole("button", { name: "Reject" }));
+ fireEvent.click(screen.getByRole("button", { name: "Undo" }));
+ await waitFor(() => expect(mocks.record).toHaveBeenCalledTimes(2));
+ mocks.record.mockClear();
const write = {
threadId: "thread-1",
messageId: "proposal-reply",
diff --git a/apps/web/src/features/assistant/conversation.tsx b/apps/web/src/features/assistant/conversation.tsx
index 886e69960..544de26e4 100644
--- a/apps/web/src/features/assistant/conversation.tsx
+++ b/apps/web/src/features/assistant/conversation.tsx
@@ -224,8 +224,8 @@ export function Conversation(props: ConversationProps) {
)
.join(" ");
const statuses = useMemo(() => {
- const map = new Map<string, Receipt>([
- ...((receipts.data?.messages ?? []) as UIMessage[]).flatMap((message) =>
+ const map = new Map<string, Receipt>(
+ ((receipts.data?.messages ?? []) as UIMessage[]).flatMap((message) =>
message.parts.flatMap((part) =>
isProposeEdits(part)
? toProposals(part, new Map(), document).map(
@@ -235,8 +235,8 @@ export function Conversation(props: ConversationProps) {
: [],
),
),
- ...[...rejections].map(([id, status]) => [id, { status }] as const),
- ]);
+ );
+ for (const [id, status] of rejections) map.set(id, { ...map.get(id), status });
// Only an undecided edit reads as replaced: one accepted or rejected (here or on another device) keeps its outcome.
for (const id of superseded.split(" ").filter(Boolean))
if ((map.get(id)?.status ?? "pending") === "pending") map.set(id, { status: "rejected", superseded: true });
diff --git a/docs/guides/using-the-assistant.mdx b/docs/guides/using-the-assistant.mdx
index 73759ef16..3e8b70b40 100644
--- a/docs/guides/using-the-assistant.mdx
+++ b/docs/guides/using-the-assistant.mdx
@@ -112,6 +112,15 @@ A request involving fields, entries or sections appears as one card for the enti
A small wording change marks only the words it changes: removed words struck through, added words highlighted. A rewrite shows the old and new text whole.
+After undoing a rejection, you can select **Edit**, change the text and select **Save wording**. The card shows **Edited by you** once the saved wording is read back. Your document changes only when you select **Accept**; Undo and Redo then follow that reviewed wording.
+
+<Frame caption="Reviewed wording on a fictional resume, reopened after accepting and reloading.">
+ <img
+ src="/images/guides/using-the-assistant/restored-reviewed-wording.png"
+ alt="An opened Summary edit with the original paragraph struck through, Audited the fictional checkout flow with keyboard users highlighted, and Edited by you beneath it"
+ />
+</Frame>
+
Each set is headed by what the edits do together, as the assistant titled it, and how many there are: for example **Tailor to the Lumen posting · 3 proposed edits**. An edit that adds a passage after an existing one shows **Adds after:** and that passage, then the new text, one line per new bullet. An edit whose new text says something your document doesn't, however small, shows **New detail: check it's true**. **Accept all** leaves those out (the button reads **Accept the others**), so you accept each one yourself after checking it.
Before accepting resume edits, **Page fit** compares the printed page count before and after the edits eligible for **Accept all** (or **Accept the others**). **Estimated overflow change** shows the signed change in spill lines: a positive number adds overflow, a negative number reduces it. Measurement uses private copies with the current design and does not save changes. Edits open for rewriting and new details needing individual confirmation are left out. If measurement fails, check the page preview before accepting.
diff --git a/docs/images/guides/using-the-assistant/restored-reviewed-wording.png b/docs/images/guides/using-the-assistant/restored-reviewed-wording.png
new file mode 100644
index 000000000..3a3af0a39
Binary files /dev/null and b/docs/images/guides/using-the-assistant/restored-reviewed-wording.png differ
diff --git a/tests/e2e/specs/assistant-reviewed-wording.spec.ts b/tests/e2e/specs/assistant-reviewed-wording.spec.ts
new file mode 100644
index 000000000..99d34a66d
--- /dev/null
+++ b/tests/e2e/specs/assistant-reviewed-wording.spec.ts
@@ -0,0 +1,66 @@
+import { approveLocalStubOperations } from "../fixtures/ai-consent";
+import { startAiStub } from "../fixtures/ai-stub";
+import { createSampleResumeFromDashboard } from "../fixtures/resume";
+import { expect, test } from "../fixtures/test";
+
+let stub: Awaited<ReturnType<typeof startAiStub>>;
+test.beforeAll(async () => {
+ stub = await startAiStub();
+});
+test.afterAll(async () => {
+ await stub.close();
+});
+
+test("restored assistant edits save reviewed wording through acceptance, Undo, Redo and reload", async ({
+ authPage: page,
+}, info) => {
+ await approveLocalStubOperations(page);
+ const provider = await page.request.post("/api/openapi/ai-providers", {
+ data: {
+ label: "Fictional review connection",
+ provider: "openai-compatible",
+ model: "stub",
+ baseURL: stub.baseURL,
+ apiKey: "stub-key",
+ },
+ });
+ await expect(provider).toBeOK();
+ await expect(await page.request.post(`/api/openapi/ai-providers/${(await provider.json()).id}/test`)).toBeOK();
+ await createSampleResumeFromDashboard(page, info);
+ const id = new URL(page.url()).pathname.split("/").at(-1);
+ const read = async () => {
+ const response = await page.request.get(`/api/openapi/resumes/${id}`);
+ await expect(response).toBeOK();
+ return (await response.json()).data;
+ };
+ const original = await read();
+ await page.getByRole("button", { name: "Assistant", exact: true }).click();
+ const assistant = page.getByRole("region", { name: "Assistant", exact: true });
+ await assistant.getByLabel("Message the assistant").fill("Propose overlapping edits");
+ await assistant.getByRole("button", { name: "Send", exact: true }).click();
+ const edits = assistant.getByRole("list", { name: "Proposed edits" });
+ await expect(edits.locator("[data-proposal-index]")).toHaveCount(4);
+ await expect(assistant.getByRole("button", { name: "Stop", exact: true })).toBeHidden();
+ await assistant.getByRole("button", { name: "Reject all", exact: true }).click();
+ const first = edits.locator("[data-proposal-index]").first();
+ await first.getByRole("button", { name: "Undo", exact: true }).click();
+ await first.getByRole("button", { name: "Edit", exact: true }).click();
+ const wording = "Audited the fictional checkout flow with keyboard users.";
+ await first.getByLabel("Your wording").fill(wording);
+ await first.getByRole("button", { name: "Save wording", exact: true }).click();
+ await expect(first.getByText("Edited by you", { exact: true })).toBeVisible();
+ await expect(first.locator("ins")).toContainText(wording);
+ expect(await read()).toEqual(original);
+ await first.getByRole("button", { name: "Accept", exact: true }).click();
+ await expect.poll(async () => (await read()).summary.content).toContain(wording);
+ await page.getByRole("button", { name: "Undo", exact: true }).first().click();
+ await expect.poll(async () => (await read()).summary.content).toBe(original.summary.content);
+ await page.getByRole("button", { name: "Redo", exact: true }).click();
+ await expect.poll(async () => (await read()).summary.content).toContain(wording);
+ await page.reload();
+ await expect(edits.getByText("Applied", { exact: true })).toHaveCount(1);
+ await expect(edits.locator("[data-proposal-index]").filter({ hasText: "Rejected" })).toHaveCount(3);
+ await first.getByRole("button", { name: "Show edit 1", exact: true }).click();
+ await expect(first.locator("ins")).toContainText(wording);
+ await edits.screenshot({ path: info.outputPath("reviewed-wording.png") });
+});