Skip to content

Commit 0cadca8

Browse files
authored
Preserve composer drafts during Refresh (#14)
* Preserve composer drafts during review refresh * Expose retained draft selection to assistive technology
1 parent 5bb9c49 commit 0cadca8

3 files changed

Lines changed: 88 additions & 5 deletions

File tree

‎docs/implementation/read-only-review.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,13 @@ The documentation-only review after adding `AGENTS.md` exposed one more concrete
110110
The follow-up review exposed the same active-job marker missing from the initial review response. Reloading during provider settlement could therefore expose Retry and stop polling. Initial loads and action responses now include the marker used by question polling; the browser regression reloads during settlement and confirms Retry remains hidden until the invocation finishes.
111111

112112
The next review made assignment drift concrete for item-level answers without snippet references. Each answer now records a hash of the changed segments supplied for its item. Moving code into or out of that item preserves the answer but labels it as earlier review context and rejects retrying the old question; a regression assigns new code without changing the snapshot or plan revision, checks the historical marker, and proves no second agent invocation starts.
113+
114+
## Refresh draft preservation (#13)
115+
116+
Held-response browser regressions reproduced Refresh replacing newer question/change text with the pre-request draft, losing text entered after switching items and modes, and hiding a draft when its item was removed. Five cases failed before the fix; the failed-refresh recovery case already passed. All six focused cases pass after capturing the current draft immediately before applying the response and on failure.
117+
118+
The browser owns unsent text, mode, navigation, and attachments; the refreshed response owns the persisted plan, approvals, notes, and snapshot. Refresh remains serialized with review actions and invalidates older question polls through the existing generation counter. A valid attached snippet survives; changed snapshot or assignment context keeps the text and marks the attachment outdated, blocking submission until it is removed or reselected. Removed items with drafts remain accessible as retained-draft rows, with submission disabled and instructions to copy the text to a current item. These drafts remain page-local and do not survive a browser reload.
119+
120+
The regression gate is `npm run test:browser -- --grep 'during refresh'`. It checks visible drafts and refreshed durable approval/snapshot/plan state, and confirms no draft was accidentally saved as a note. Issues #10 (review edge cases), #12 (polling efficiency), and #3 (human go/no-go experiment) remain separate work.
121+
122+
PR #14 review round 1 found that retained-draft rows omitted the regular rows' `aria-current` state. A browser assertion reproduced the missing attribute. Retained rows now expose their selected state; the regression checks selection, navigation away, and selection again. No findings were declined.

‎test/browser/review.spec.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,69 @@ test('outdated questions explain how to continue without offering a broken retry
236236
await expect(page.getByText('This question refers to an earlier review. Ask again against the current code.',{exact:true})).toBeVisible();
237237
await expect(page.getByRole('heading',{name:'Bound exponential retries'})).toBeVisible();
238238
});
239+
for(const kind of ['question','change']) test(`preserves ${kind} edits and snippets during refresh`,async({page})=>{
240+
await page.goto(app.url);await expect(page.getByRole('heading',{name:'Bound exponential retries'})).toBeVisible();
241+
await page.locator('.added [data-line]').first().click();
242+
await page.getByRole('button',{name:kind==='question'?'Ask about selection':'Request change to selection',exact:true}).click();
243+
const composer=page.locator('#message');await composer.fill('Before refresh');
244+
let release!:()=>void,arrived!:()=>void;const held=new Promise<void>(resolve=>release=resolve),started=new Promise<void>(resolve=>arrived=resolve);
245+
await page.route('**/api/review',async route=>{arrived();await held;await route.continue();});
246+
await page.getByRole('button',{name:'Refresh',exact:true}).click();await started;
247+
await composer.fill('Edited during refresh');
248+
app.service.act({action:'approve',item:'P3',confirmNoChange:true,token:app.service.load().token});
249+
release();await expect(page.getByText('1 of 3 approved')).toBeVisible();
250+
await expect(composer).toHaveValue('Edited during refresh');
251+
await expect(page.locator(kind==='question'?'#ask':'#request')).toHaveAttribute('aria-pressed','true');
252+
await expect(page.locator('#attachment')).toContainText('retry.ts');await expect(page.locator('#attachment')).not.toContainText('Outdated');
253+
await expect(page.locator('#save-note')).toBeEnabled();
254+
expect(app.service.load().approved).toBe(1);expect(app.service.load().notes).toHaveLength(0);
255+
});
256+
for(const scenario of ['navigation','snapshot','removed item','failure']) test(`preserves drafts during refresh with ${scenario}`,async({page})=>{
257+
await page.goto(app.url);await expect(page.getByRole('heading',{name:'Bound exponential retries'})).toBeVisible();
258+
await page.locator('.added [data-line]').first().click();await page.getByRole('button',{name:'Ask about selection',exact:true}).click();
259+
await page.locator('#message').fill('Before refresh');
260+
let release!:()=>void,arrived!:()=>void;const held=new Promise<void>(resolve=>release=resolve),started=new Promise<void>(resolve=>arrived=resolve);
261+
await page.route('**/api/review',async route=>{arrived();await held;if(scenario==='failure')await route.fulfill({status:500,json:{error:'Temporary read failure'}});else await route.continue();});
262+
await page.getByRole('button',{name:'Refresh',exact:true}).click();await started;
263+
await page.locator('#message').fill('Latest question');
264+
if(scenario==='navigation'){
265+
await page.getByRole('button',{name:/P2 Document retry behavior/}).click();
266+
await page.getByRole('button',{name:'Request change',exact:true}).click();await page.locator('#message').fill('Latest change request');
267+
}
268+
if(scenario==='snapshot')execFileSync('git',['-c','core.hooksPath=/dev/null','commit','--allow-empty','-m','New snapshot'],{cwd:app.service.config.repository,stdio:'pipe'});
269+
if(scenario==='removed item'){
270+
const service=app.service,identity=service.config.identity,plan=service.store.getPlan(identity);
271+
service.store.importRevision(JSON.stringify({...plan,items:plan.items.filter(item=>item.id!=='P1').map(item=>({...item,depends_on:[]}))}),'json',{identity,issue:plan.issue,baseEntries:['retry.ts','README.md','run.sh'].map(path=>({path,kind:'file' as const})),pathKey:path=>path,allowedCommands:[]},plan.revision);
272+
}
273+
release();
274+
if(scenario==='failure'){
275+
await expect(page.locator('#banner')).toContainText('Temporary read failure');await page.unroute('**/api/review');
276+
await page.getByRole('button',{name:'Refresh',exact:true}).click();
277+
}
278+
await expect(page.locator('#banner')).not.toContainText('Linking changes');await expect(page.locator('#banner')).not.toContainText('Temporary read failure');
279+
if(scenario==='navigation'){
280+
await expect(page.getByRole('heading',{name:'Document retry behavior'})).toBeVisible();
281+
await expect(page.locator('#message')).toHaveValue('Latest change request');await expect(page.locator('#request')).toHaveAttribute('aria-pressed','true');
282+
await page.getByRole('button',{name:/P1 Bound exponential retries/}).click();await page.getByRole('button',{name:'Ask',exact:true}).click();
283+
}
284+
await expect(page.locator('#message')).toHaveValue('Latest question');
285+
if(scenario==='snapshot'){
286+
await expect(page.locator('#attachment')).toContainText('Outdated');await expect(page.locator('#save-note')).toBeDisabled();
287+
expect(app.service.load().snapshot.head).toBe(execFileSync('git',['rev-parse','HEAD'],{cwd:app.service.config.repository,encoding:'utf8'}).trim());
288+
}
289+
if(scenario==='removed item'){
290+
await expect(page.locator('#item-details')).toContainText('no longer in the plan');await expect(page.locator('#save-note')).toBeDisabled();
291+
await expect(page.getByRole('button',{name:'! P1 · Retained draft',exact:true})).toHaveAttribute('aria-current','true');
292+
await expect(page.getByRole('button',{name:/P1 Bound exponential retries/})).toHaveCount(0);
293+
await page.getByRole('button',{name:/P2 Document retry behavior/}).click();
294+
await expect(page.getByRole('button',{name:'! P1 · Retained draft',exact:true})).toHaveAttribute('aria-current','false');
295+
await page.getByRole('button',{name:'! P1 · Retained draft',exact:true}).click();
296+
await expect(page.getByRole('button',{name:'! P1 · Retained draft',exact:true})).toHaveAttribute('aria-current','true');
297+
await expect(page.locator('#message')).toHaveValue('Latest question');await expect(page.locator('#message')).toBeEnabled();
298+
expect(app.service.load().items.map(item=>item.id)).toEqual(['P2','P3']);
299+
}
300+
expect(app.service.load().notes).toHaveLength(0);
301+
});
239302
for(const switchItem of [false,true]) test(`preserves edits made while a question submission is in flight (switch item: ${switchItem})`,async({page})=>{
240303
await page.goto(app.url);await expect(page.getByRole('heading',{name:'Bound exponential retries'})).toBeVisible();
241304
let release!:()=>void;const held=new Promise<void>(resolve=>release=resolve);

‎web/public/app.js‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,15 @@ async function refresh() {
8181
$("banner").textContent = "Linking changes to plan items…";
8282
try {
8383
rememberDraft();
84-
data = await api("/api/review");
84+
const updated = await api("/api/review");
85+
rememberDraft();
86+
data = updated;
8587
snippetSelection = null;
8688
selected ??= data.items[0]?.id || "Unplanned";
8789
since = data.items.find((item) => item.id === selected)?.state === "stale";
8890
render();
8991
} catch (error) {
92+
rememberDraft();
9093
showFailure(
9194
`Could not read this branch’s history. ${error.message} Use Refresh to retry.`,
9295
);
@@ -126,7 +129,12 @@ function select(id) {
126129
}
127130
function render() {
128131
const item = data.items.find((item) => item.id === selected);
129-
if (!item && !["Unplanned", "Ambiguous", "Accepted"].includes(selected)) {
132+
const retainedItems = [...new Set([
133+
...[...drafts].filter(([, text]) => text.length).map(([key]) => key.split(":")[0]),
134+
...[...attachments.keys()].map((key) => key.split(":")[0]),
135+
])].filter((id) => !data.items.some((entry) => entry.id === id) && !["Unplanned", "Ambiguous", "Accepted"].includes(id));
136+
const retained = retainedItems.includes(selected);
137+
if (!item && !retained && !["Unplanned", "Ambiguous", "Accepted"].includes(selected)) {
130138
selected = data.items[0]?.id || "Unplanned";
131139
return render();
132140
}
@@ -164,7 +172,9 @@ function render() {
164172
(row) =>
165173
`<button class="plan-row ${row === selected ? "selected" : ""}" data-select="${row}"><span class="row-title ${row === "Unplanned" ? "bad" : row === "Ambiguous" ? "warn" : "muted"}">${row === "Unplanned" ? "✕" : row === "Ambiguous" ? "!" : "✓"} ${row}${row === "Unplanned" ? " changes" : ""}<span class="count">${data.segments.filter((s) => s.row === row).length}</span></span></button>`,
166174
)
167-
.join("");
175+
.join("") + retainedItems.map((id) =>
176+
`<button class="plan-row ${id === selected ? "selected" : ""}" data-select="${esc(id)}" aria-current="${id === selected ? "true" : "false"}"><span class="warn">! ${esc(id)} · Retained draft</span></button>`,
177+
).join("");
168178
document
169179
.querySelectorAll("[data-select]")
170180
.forEach((button) =>
@@ -174,7 +184,7 @@ function render() {
174184
$("item-title").textContent = item?.title || selected;
175185
$("item-details").innerHTML = item
176186
? `<p>${esc(item.intent)}</p>${item.reasons.map((reason) => `<p class="warn">! Stale: ${esc(reason)}</p>`).join("")}`
177-
: "";
187+
: retained ? '<p class="warn">This item is no longer in the plan. Your draft is retained in this page. Copy the text, select a current plan item, and reselect any code before submitting.</p>' : "";
178188
$("approve").hidden = !item;
179189
$("approve").textContent = item?.ambiguousCount
180190
? "Resolve ambiguous changes"
@@ -214,7 +224,7 @@ function render() {
214224
}),
215225
);
216226
renderNotes();
217-
$("message").disabled = !item;
227+
$("message").disabled = !item && !retained;
218228
$("save-note").disabled = !item;
219229
$("message").value = drafts.get(`${selected}:${mode}`) || "";
220230
renderCode();

0 commit comments

Comments
 (0)