Retain held Review references when accepted positioning is unavailable

This commit is contained in:
Nick Beckley 2026-11-23 14:16:01 +00:00
parent d55206d8c3
commit 3b1491f1a4
3 changed files with 6 additions and 5 deletions

View File

@ -24,7 +24,7 @@ A future editor can use the same identifier-only contract and existing authentic
## Clients and Hold
Review publishes deliberate paragraph clicks, paragraph keyboard navigation and chapter/scene selectors, including when Word is closed. Accepted content remains authoritative. Incoming focus uses the existing partial chapter/scene positioning pipeline, preserves open editors and review tools, and explains missing precise paragraph/scene mapping before showing a deterministic scene/chapter fallback. Scrolling does not publish.
Review publishes deliberate paragraph clicks, paragraph keyboard navigation and chapter/scene selectors, including when Word is closed. Accepted content remains authoritative. Incoming focus uses the existing partial chapter/scene positioning pipeline, preserves open editors and review tools, and explains missing precise paragraph/scene mapping before showing a deterministic scene/chapter fallback. A missing held passage stops positioning and offers local reselection/Release, without moving to another paragraph. Scrolling does not publish.
Context dropdown, Previous, Next and Go to Focus use shared focus directly, without a Word navigation request. Each window retains its panes, tools, divider, cached tab state and layout. Snapshot windows also keep data notifications. Focus changes only invalidate panels whose scope changed. Data invalidation is independent of Hold and conservatively refreshes affected visible relationship/character panels across scenes; hidden panels are marked stale until activated. Structural invalidation retains the held reference and offers another local selection or Release Hold.
@ -42,7 +42,7 @@ Explicit Open in Word controls are retained, including paragraph navigation: phy
- Native portable regression harness: **320 passing checks**, including the dedicated per-window Hold/revision cases. These exercise managed production logic and IPC, not Word COM.
- Development rollback-only SQL tests cover no initial publication, canonical paragraph resolution, monotonic revisions, unchanged-target suppression, replay rejection, held resolution without mutation, canonical cross-chapter stepping, chapter-only and empty-chapter boundaries, endpoint paragraph preservation, invalid references, verified Word offsets, exact-session isolation and authorisation. The updated historical six-phase SQL regression also passes with no implicit seed/redirection.
- Sixteen real concurrent SQL connections verify contiguous unique accepted revisions and a final durable read equal to the highest revision. Real coordinator/SQL/native-queue integration also verifies Word-only publication, browser-to-Word chapter crossing, passive suppression, Hold/release, failed receipts, unsaved documents, delivery renewal after a saved Word/snapshot revision, and exact-session isolation through a recording transport.
- Real authenticated Chromium and installed standalone Chromium PWA tests use the actual controllers, SQL and SignalR with a synthetic isolated project/manuscript. They cover Context alone; Review/Context without Word; local scrolling; exact paragraphs and chapter crossing; independent Hold; local held Review navigation; refresh and release without publication; rapid and obsolete ordering; new/duplicated-window isolation; reconnect; responsive widths; hidden tabs; and relationship edits in an earlier scene refreshing both held panes. The refreshed later-scene graph is checked for the new note, not just a refresh request.
- Real authenticated Chromium and installed standalone Chromium PWA tests use the actual controllers, SQL and SignalR with a synthetic isolated project/manuscript. They cover Context alone; Review/Context without Word; local scrolling; exact paragraphs and chapter crossing; independent Hold; local held Review navigation; refresh and release without publication; rapid and obsolete ordering; new/duplicated-window isolation; reconnect; responsive widths; hidden tabs; a synthetic missing-accepted-passage resolver check that prevents held Review fallback navigation; and relationship edits in an earlier scene refreshing both held panes. The refreshed later-scene graph is checked for the new note, not just a refresh request.
- Actual loopback server restart passed: durable focus recovered, SignalR reconnected, and the held window detected an offline structural change without redirecting. Browser structural archival acceptance passed. Final public Development smoke results are recorded in deployment evidence. Browser fixtures are isolated and archived after testing; no real manuscript text or relationships are edited.
Reproducible entry points: `PlotLine.Tests --shared-focus-database <disposable-scope-file>` (rollback); `--shared-focus-browser-setup <disposable-scope-file>`; `--shared-focus-browser-host` (loopback only, real auth/SQL/hub, no hosted workers); `--shared-focus-concurrent`; `--shared-focus-cleanup`. Browser: `PlotLine.Tests/Browser/shared-manuscript-focus.cjs`, optionally `--installed`, `--structure`, or the externally coordinated `--restart` case, with private disposable identity supplied through `PD_CONTEXT_IDENTITY`. Portable native: `--shared-focus`. No credentials are in the report or repository.

View File

@ -28,7 +28,7 @@ const base=process.env.PD_SHARED_FOCUS_URL||'http://127.0.0.1:5258';
step='Next crosses chapters without Word';await b.locator('[data-context-next]').click();await scene(b,s.scene3);await review.waitForSelector(`.manuscript-reader [data-paragraph-id="${s.paragraph3}"]`);await scene(a,s.scene2);
assert.equal(heldFocusFetches,0,'shared focus alone does not refetch a held pane');await b.click('[data-context-previous]');await scene(b,s.scene2);await b.click('[data-context-next]');await scene(b,s.scene3);const latest=(await current(b)).version;await a.click('[data-context-go-focus]');await scene(a,s.scene3);assert.equal(await a.evaluate(()=>PlotDirectorSharedFocus.held),true);assert.equal((await current(a)).version,latest);await a.selectOption('[data-context-scene]',String(s.scene2));await scene(a,s.scene2);await a.reload();await ready(a);await scene(a,s.scene2);assert.equal(await a.evaluate(()=>PlotDirectorSharedFocus.held),true);
step='release catches latest without publishing';await a.click('[data-shared-focus-hold]');await scene(a,s.scene3);assert.equal((await current(a)).version,latest);assert.equal((await current(b)).version,latest);
step='held Review local navigation';await review.locator('[data-shared-focus-hold]:visible').first().click();await review.evaluate(s=>PlotDirectorSharedFocus.navigate({chapterID:s.chapter1,paragraphID:s.paragraph1}),s);await review.waitForSelector(`.manuscript-reader [data-paragraph-id="${s.paragraph1}"]`);assert.equal((await current(review)).version,latest);await scene(b,s.scene3);await review.locator('[data-shared-focus-hold]:visible').first().click();await review.waitForSelector(`.manuscript-reader [data-paragraph-id="${s.paragraph3}"]`);
step='held Review local navigation';await review.locator('[data-shared-focus-hold]:visible').first().click();await review.evaluate(s=>PlotDirectorSharedFocus.navigate({chapterID:s.chapter1,paragraphID:s.paragraph1}),s);await review.waitForSelector(`.manuscript-reader [data-paragraph-id="${s.paragraph1}"]`);assert.equal((await current(review)).version,latest);await scene(b,s.scene3);await review.evaluate(()=>{const r=document.querySelector('.manuscript-reader'),resolve=r.readerResolveFocus,locate=r.readerLocateFocus;window.__heldFallbackMoves=0;r.readerResolveFocus=()=>({paragraph:r.querySelector('[data-paragraph-id]'),precise:false});r.readerLocateFocus=(...args)=>{window.__heldFallbackMoves++;return locate(...args);};window.__restoreHeldReader=()=>{r.readerResolveFocus=resolve;r.readerLocateFocus=locate;};document.dispatchEvent(new Event('reader:updated'));});await review.waitForFunction(()=>/held reference no longer/.test(document.querySelector('[data-review-focus-notice]').textContent));await review.waitForTimeout(120);assert.equal(await review.evaluate(()=>window.__heldFallbackMoves),0,'a missing held accepted passage cannot trigger fallback navigation');console.log('PASS held Review missing accepted-passage resolver: no fallback navigation or retarget.');await review.evaluate(()=>window.__restoreHeldReader());await review.locator('[data-shared-focus-hold]:visible').first().click();await review.waitForSelector(`.manuscript-reader [data-paragraph-id="${s.paragraph3}"]`);
step='rapid navigation serializes latest intent';await b.evaluate(async s=>{void PlotDirectorSharedFocus.navigate({sceneID:s.scene1});void PlotDirectorSharedFocus.navigate({sceneID:s.scene2});void PlotDirectorSharedFocus.navigate({sceneID:s.scene3});},s);await b.waitForFunction(s=>PlotDirectorSharedFocus.shared.sceneID===s.scene3&&PlotDirectorSharedFocus.shared.version>0,s);await b.waitForTimeout(700);assert.equal((await current(b)).sceneID,s.scene3);
step='duplicate/delayed events cannot overwrite';const stable=await current(b);await b.evaluate(p=>{const conn=document.querySelector('[data-context-workspace]').contextController.connection;const handlers=Object.values(conn).find(v=>Array.isArray(v?.manuscriptfocuschanged))?.manuscriptfocuschanged;if(!handlers)throw Error('Focus receiver was not registered');for(const handler of handlers)handler({...p,version:p.version-1,sceneID:1});},stable);assert.equal((await current(b)).sceneID,s.scene3);
step='held cross-scene relationship invalidation in split panes';await a.click('[data-shared-focus-hold]');await a.selectOption('[data-context-scene]',String(s.scene2));await scene(a,s.scene2);await a.selectOption('[data-context-layout]','columns');await a.selectOption('[data-context-pane="0"] [data-context-tab]','relationships');await a.selectOption('[data-context-pane="1"] [data-context-tab]','characters');await a.waitForSelector('[data-context-pane="0"] [data-context-tab-fragment]');await a.waitForSelector('[data-context-pane="1"] [data-context-tab-fragment]');
@ -40,7 +40,7 @@ const base=process.env.PD_SHARED_FOCUS_URL||'http://127.0.0.1:5258';
step='new window does not inherit Hold';const fresh=await surface(contextURL);await ready(fresh);await scene(fresh,s.scene3);assert.equal(await fresh.evaluate(()=>PlotDirectorSharedFocus.held),false);
if(s.emptyChapter){step='chapter-only and empty-chapter toolbar boundaries';const command=async name=>{const menu=review.locator('.pd-ribbon-panel:not([hidden]) .pd-ribbon-focus details[data-compact=true]');if(await menu.count()&&!await menu.evaluate(n=>n.open))await menu.locator('summary').click();await review.locator('.pd-ribbon-panel:not([hidden]) [data-global-focus='+name+']').click();await review.waitForFunction(()=>document.querySelector('.pd-ribbon-panel:not([hidden]) [data-global-focus=previous]')?.disabled===false);};await review.evaluate(s=>PlotDirectorNarrativeFocus.set({chapterID:s.chapter2}),s);await review.waitForFunction(s=>PlotDirectorSharedFocus.local.chapterID===s.chapter2&&!PlotDirectorSharedFocus.local.sceneID,s);await command('next');await scene(b,s.scene3);await review.evaluate(s=>PlotDirectorNarrativeFocus.set({chapterID:s.emptyChapter}),s);await review.waitForFunction(s=>document.querySelector('.manuscript-reader').dataset.chapterId===String(s.emptyChapter),s);await command('next');await scene(b,s.scene3);await review.evaluate(s=>PlotDirectorNarrativeFocus.set({chapterID:s.emptyChapter}),s);await review.waitForFunction(s=>document.querySelector('.manuscript-reader').dataset.chapterId===String(s.emptyChapter),s);await command('previous');await scene(b,s.scene2);await scene(a,s.scene2);await review.evaluate(s=>PlotDirectorNarrativeFocus.set({chapterID:s.chapter2,sceneID:s.scene3}),s);await scene(b,s.scene3);console.log('PASS actual Review toolbar: chapter-only Next stays in its own chapter; empty-chapter Previous/Next reaches the canonical neighbor without moving held Context.');}
step='duplicated session state cannot inherit Hold';const clone=await c.newPage();const storage=await a.evaluate(()=>Object.fromEntries(Object.entries(sessionStorage).filter(([k])=>k.startsWith('pd.shared-focus')||k==='plotdirector.context.window.v1')));await clone.addInitScript(values=>{for(const[k,v]of Object.entries(values))sessionStorage.setItem(k,v);},storage);await clone.goto(contextURL);await ready(clone);await clone.waitForFunction(id=>!PlotDirectorSharedFocus.held&&PlotDirectorSharedFocus.windowID!==id,await a.evaluate(()=>PlotDirectorSharedFocus.windowID));await scene(clone,s.scene3);
step='hidden affected tab is fetched when activated';const beforeHidden=invalidated;await a.selectOption('[data-context-pane="1"] [data-context-tab]','overview');await a.waitForTimeout(600);assert(invalidated>beforeHidden);await scene(a,s.scene2);
step='hidden affected cached tab is fetched when activated';const beforeHidden=invalidated;await a.selectOption('[data-context-pane="0"] [data-context-tab]','overview');await a.waitForTimeout(600);assert(invalidated>beforeHidden);await scene(a,s.scene2);
step='responsive Hold control';for(const width of[1500,760,390]){await a.setViewportSize({width,height:900});assert(await a.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2),'Context overflow at '+width);}await a.setViewportSize({width:1500,height:1000});
if(process.argv.includes('--restart')){step='actual server restart recovery';const revision=(await current(b)).version;await b.evaluate(()=>{const root=document.querySelector('[data-context-workspace]');root.contextController.connection.onreconnected(()=>window.__sharedFocusRestartRecovered=true);root.addEventListener('context-connection-ready',()=>window.__sharedFocusRestartRecovered=true,{once:true});});fs.writeFileSync('/tmp/shared-focus-restart-ready','ready');await b.waitForFunction(()=>window.__sharedFocusRestartRecovered,null,{timeout:55000});await scene(b,s.scene3);await a.waitForFunction(()=>[...document.querySelectorAll('[data-shared-focus-status]')].some(n=>/no longer valid/.test(n.textContent)));await scene(a,s.scene2);assert.equal(await a.evaluate(()=>PlotDirectorSharedFocus.held),true);assert.equal((await current(b)).version,revision);await a.selectOption('[data-context-scene]',String(s.scene1));await scene(a,s.scene1);assert.equal((await current(a)).version,revision);console.log('PASS actual loopback server restart: latest focus persisted, SignalR reconnected, held scene retained and an offline structural change was validated without redirect.');}
if(process.argv.includes('--structure')){step='structural archive retains held reference';const result=await edit.evaluate(async s=>{const token=document.querySelector('[name=__RequestVerificationToken]').value;const response=await fetch('/Scenes/Archive',{method:'POST',body:new URLSearchParams({id:s.scene2,chapterId:s.chapter1,__RequestVerificationToken:token})});return response.status;},s);assert.equal(result,200);await a.waitForFunction(()=>[...document.querySelectorAll('[data-shared-focus-status]')].some(n=>/no longer valid/.test(n.textContent)));await scene(a,s.scene2);assert.equal(await a.evaluate(()=>PlotDirectorSharedFocus.held),true);await a.selectOption('[data-context-scene]',String(s.scene1));await scene(a,s.scene1);assert.equal((await current(a)).sceneID,s.scene3);const version=(await current(a)).version;const archived=await edit.evaluate(async s=>{const token=document.querySelector('[name=__RequestVerificationToken]').value;return(await fetch('/Scenes/Archive',{method:'POST',body:new URLSearchParams({id:s.scene3,chapterId:s.chapter2,__RequestVerificationToken:token})})).status;},s);assert.equal(archived,200);await a.evaluate(()=>PlotDirectorSharedFocus.refresh());assert.equal((await current(a)).isValid,false);await a.evaluate(()=>{const conn=document.querySelector('[data-context-workspace]').contextController.connection;const handlers=Object.values(conn).find(v=>Array.isArray(v?.manuscriptfocuschanged))?.manuscriptfocuschanged;for(const handler of handlers||[])handler({...PlotDirectorSharedFocus.shared,isValid:true});});assert.equal((await current(a)).isValid,false,'duplicate focus packets cannot undo authoritative same-revision invalidity');await a.click('[data-shared-focus-hold]');await a.waitForFunction(()=>!PlotDirectorSharedFocus.held);await scene(a,s.scene1);assert.equal((await current(a)).version,version);assert.equal((await current(a)).isValid,false,'same-revision invalidity must replace cached validity before Release');await b.selectOption('[data-context-scene]',String(s.scene1));await b.waitForFunction(s=>PlotDirectorSharedFocus.shared.sceneID===s.scene1&&PlotDirectorSharedFocus.shared.isValid,s);console.log('PASS structural safety: local invalid reference retained; Release rejects an invalid shared point even at the same revision, retains valid local position, and does not publish.');}

View File

@ -32,6 +32,7 @@
reader=columns.querySelector('.manuscript-reader');reader._focusFilters=filters;
}
const target=reader.readerResolveFocus?.(focus);if(!target)throw Error('Current Focus is unavailable in the displayed accepted chapter.');
if(window.PlotDirectorSharedFocus?.held&&(focus.paragraphID||focus.sceneID)&&!target.precise){notice.hidden=false;notice.textContent='The held reference no longer has a precise accepted passage. Your current view is retained. Select another local reference or Release Hold.';return;}
await document.querySelector('[data-writer-review]')?.selectNarrativeParagraph?.(target.paragraph?.dataset.paragraphId||null);
if(mine!==generation||!same(focus,current())||!canChange())return;
for(const [name,value]of reader._focusFilters||[]){const select=columns.querySelector(`[data-annotation-filter="${name}"]`);if(select){select.value=value;select.dispatchEvent(new Event('change',{bubbles:true}));}}delete reader._focusFilters;
@ -50,7 +51,7 @@
document.addEventListener('reader:updated',()=>void apply(current()));
if(current()&&window.PlotDirectorSharedFocus)void apply(current());
window.addEventListener('pagehide',()=>{++generation;request?.abort();});
function selectParagraph(p){const r=p.closest('.manuscript-reader');if(!r||document.querySelector('[data-writer-review]')?.canChangeNarrative?.()===false)return;for(const item of r.querySelectorAll('[data-paragraph-id]'))item.tabIndex=item===p?0:-1;void window.PlotDirectorSharedFocus?.navigate({projectID:current()?.projectID,bookID:Number(r.dataset.bookId),chapterID:Number(r.dataset.chapterId),sceneID:Number(p.dataset.sceneId)||null,paragraphID:p.dataset.paragraphId,localSelection:true});}
function selectParagraph(p){const r=p.closest('.manuscript-reader');if(!r||document.querySelector('[data-writer-review]')?.canChangeNarrative?.()===false)return;notice.hidden=true;for(const item of r.querySelectorAll('[data-paragraph-id]'))item.tabIndex=item===p?0:-1;void window.PlotDirectorSharedFocus?.navigate({projectID:current()?.projectID,bookID:Number(r.dataset.bookId),chapterID:Number(r.dataset.chapterId),sceneID:Number(p.dataset.sceneId)||null,paragraphID:p.dataset.paragraphId,localSelection:true});}
document.addEventListener('click',event=>{if(!event.isTrusted)return;const p=event.target.closest('.manuscript-reader [data-paragraph-id]');if(p)selectParagraph(p);const link=event.target.closest('.reader-chapter-navigation a[href]');if(link){event.preventDefault();const chapter=Number(new URL(link.href).searchParams.get('chapterId'));if(chapter)void window.PlotDirectorSharedFocus?.navigate({chapterID:chapter});}});
document.addEventListener('submit',event=>{if(event.defaultPrevented)return;const form=event.target;if(form.closest('.reader-chapter-navigation')){event.preventDefault();const chapter=Number(new FormData(form).get('chapterId'));if(chapter)void window.PlotDirectorSharedFocus?.navigate({chapterID:chapter});}});
document.addEventListener('keydown',event=>{if(!event.target.matches('.manuscript-reader [data-paragraph-id]')||!['ArrowUp','ArrowDown','Home','End'].includes(event.key))return;event.preventDefault();const paragraphs=[...event.target.closest('.manuscript-reader').querySelectorAll('[data-paragraph-id]')],index=paragraphs.indexOf(event.target),next=event.key==='Home'?0:event.key==='End'?paragraphs.length-1:Math.max(0,Math.min(paragraphs.length-1,index+(event.key==='ArrowDown'?1:-1)));const p=paragraphs[next];p.focus({preventScroll:true});p.scrollIntoView({block:'nearest'});p.click();selectParagraph(p);});