From fcc81fb0155f62adc91c076e847de5cf81b222df Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Sat, 21 Nov 2026 22:36:21 +0000 Subject: [PATCH] Validate Context fragments against each registered navigation scope --- .../Unified-Context-Workspace-Foundation-20261121.md | 2 +- .../Browser/context-workspace-foundation.cjs | 11 +++++++++++ PlotLine/wwwroot/js/context-workspace.js | 5 +++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Docs/Writer/Unified-Context-Workspace-Foundation-20261121.md b/Docs/Writer/Unified-Context-Workspace-Foundation-20261121.md index af98b9d1..69a96ae7 100644 --- a/Docs/Writer/Unified-Context-Workspace-Foundation-20261121.md +++ b/Docs/Writer/Unified-Context-Workspace-Foundation-20261121.md @@ -96,7 +96,7 @@ The Scene editor, Writer Chapter workflows, full Maps/Floor Plans/Relationships/ - Normal `dotnet build PlotLine.slnx`: clean build, zero warnings/errors at the recorded gate. - Full executable regression harness: 673 PASS lines, exit 0; includes updated native session/access/ownership/reference-data checks and existing native command/authentication suites. Additional notification-boundary assertions are included in focused Writing integration qualification. - `--writing-integration`: authoritative reference hydration, scope/access, exact native session, unsaved/stale mappings, during-load changes, chronology/provenance and request reuse. -- `Browser/context-workspace-foundation.cjs`: real compiled Razor shell and both partials in the isolated loopback host, with synthetic reference data and controllable HTTP/SignalR inputs. Covers layouts, pointer/keyboard divider, same/different tabs, shared reads, hidden staleness, same-scene invalidation, rapid chapter/scene races, dirty/busy deferral, access/session failures, reconnect, native ambiguity/document selection, Office fallback/native precedence, independent windows, cloned storage (BroadcastChannel and storage-event fallback), denied storage, persistence, pinned snapshots and Office/Intent launch compatibility. +- `Browser/context-workspace-foundation.cjs`: real compiled Razor shell and both partials in the isolated loopback host, with synthetic reference data and controllable HTTP/SignalR inputs. Covers layouts, pointer/keyboard divider, same/different tabs, shared reads, generic None/Book/Chapter/Scene/Paragraph hierarchy using test-only registration metadata, hidden staleness, same-scene invalidation, rapid chapter/scene races, dirty/busy deferral, access/session failures, reconnect, native ambiguity/document selection, Office fallback/native precedence, independent windows, cloned storage (BroadcastChannel and storage-event fallback), denied storage, persistence, pinned snapshots and Office/Intent launch compatibility. - Browser sizes include 1366×768, 760×768, 683×384 and 480×700 at 125% CSS zoom; shell/card reflow and no document-wide horizontal overflow are checked. The 683×384 viewport approximates the CSS space at 200% on a 1366×768 display. - Shared notifications browser checks pass in browser and simulated standalone presentation. Existing Evidence request/cancel/isolation checks remain applicable. - Standalone presentation is simulated Chromium qualification. Physical installed-PWA, Windows Word/VSTO and OS-level zoom/assistive-technology acceptance remain manual; these are not claimed as automated physical tests. diff --git a/PlotLine.Tests/Browser/context-workspace-foundation.cjs b/PlotLine.Tests/Browser/context-workspace-foundation.cjs index 77bae486..0ea53aa2 100644 --- a/PlotLine.Tests/Browser/context-workspace-foundation.cjs +++ b/PlotLine.Tests/Browser/context-workspace-foundation.cjs @@ -71,6 +71,17 @@ const lease=(extra={})=>({instanceId:'11111111-1111-4111-8111-111111111111',sess } await page.evaluate(()=>{document.documentElement.style.zoom='1';Object.defineProperty(navigator,'standalone',{value:true});}); step='pinned snapshot';leases=[lease({sceneId:23,chapterId:11})];const pinned=await context.newPage();await pinned.goto(base+'/Writing/Context?pinned=true&sceneId=22');await pinned.waitForSelector('[data-context-tab-fragment]');assert.equal(await pinned.evaluate(()=>contextConnections.length),0);assert.equal(await pinned.locator('[data-context-tab-fragment]').getAttribute('data-scene-id'),'22');await pinned.selectOption('[data-context-scene]','23');await pinned.waitForSelector('[data-context-tab-fragment][data-scene-id="23"]');await pinned.close(); + step='generic hierarchical registration scopes'; + for(const declared of ['None','Book','Chapter','Scene','Paragraph']){ + const generic=await context.newPage();let count=0; + await generic.route('**/Writing/Context?pinned=true*',async route=>{const response=await route.fetch();await route.fulfill({response,body:(await response.text()).replaceAll('"scope":"Scene"','"scope":"'+declared+'"')});}); + await generic.route('**/Writing/Context/Tabs/*',async route=>{count++;const params=new URL(route.request().url()).searchParams,level=['None','Book','Chapter','Scene','Paragraph'].indexOf(declared),fields=['projectId','bookId','chapterId','sceneId','paragraphId'];const attributes=fields.slice(0,level===0?0:level+1).filter(f=>params.has(f)).map(f=>'data-'+f.replace(/[A-Z]/g,c=>'-'+c.toLowerCase())+'="'+params.get(f)+'"').join(' ');await route.fulfill({contentType:'text/html',body:'

Generic reference

'});}); + await generic.goto(base+'/Writing/Context?pinned=true');await generic.waitForSelector('[data-context-tab-fragment]');assert.equal(count,1);assert.equal(await generic.evaluate(()=>document.querySelector('[data-context-workspace]').contextController.position.paragraphId),null); + const move=async(chapterId,sceneId,paragraphId=null)=>{const before=count;await generic.evaluate(p=>document.querySelector('[data-context-workspace]').contextController.setPosition(p),{projectId:7,bookId:12,chapterId,sceneId,paragraphId});await generic.waitForTimeout(70);return count-before;}; + assert.equal(await move(10,23),['Scene','Paragraph'].includes(declared)?1:0,declared+' scene policy'); + assert.equal(await move(11,24),['Chapter','Scene','Paragraph'].includes(declared)?1:0,declared+' chapter policy'); + assert.equal(await move(11,24,'provided-paragraph'),declared==='Paragraph'?1:0,declared+' paragraph policy');await generic.close(); + } step='storage-event clone fallback'; const fallback=await context.newPage();await fallback.addInitScript(()=>Object.defineProperty(window,'BroadcastChannel',{value:undefined}));await fallback.goto(base+'/Writing/Context');await fallback.waitForSelector('[data-context-tab-fragment]');await fallback.selectOption('[data-context-layout]','rows');const fallbackId=await fallback.evaluate(()=>document.querySelector('[data-context-workspace]').contextController.windowId); const fallbackClone=await context.newPage();await fallbackClone.addInitScript(id=>{Object.defineProperty(window,'BroadcastChannel',{value:undefined});sessionStorage.setItem('plotdirector.context.window.v1',id);},fallbackId);await fallbackClone.goto(base+'/Writing/Context');await fallbackClone.waitForFunction(id=>document.querySelector('[data-context-workspace]')?.contextController?.windowId!==id,fallbackId);assert.equal(await fallbackClone.locator('[data-context-layout]').inputValue(),'single');await fallback.close();await fallbackClone.close(); diff --git a/PlotLine/wwwroot/js/context-workspace.js b/PlotLine/wwwroot/js/context-workspace.js index 86b3bf23..33448db6 100644 --- a/PlotLine/wwwroot/js/context-workspace.js +++ b/PlotLine/wwwroot/js/context-workspace.js @@ -99,7 +99,8 @@ if(stopped||epoch!==generation||request!==pane.revision||state.panes[pane.index].tab!==tab.id||!visible(pane))return; if(guarded(record)){pane.status.textContent='Updates available · refresh deferred while editing or busy.';return;} const node=fragment(html); - if(position.sceneId&&Number(node.dataset.sceneId)!==position.sceneId)throw Error('Reference position changed. Refresh saved data to retry.'); + const level=scopes.indexOf(tab.scope),count=level<=0?0:level+1; + if(fields.slice(0,count).some(field=>position[field]!=null&&String(node.dataset[field])!==String(position[field])))throw Error('Reference position changed. Refresh saved data to retry.'); const focused=pane.host.contains(document.activeElement)?document.activeElement:null; const focusHref=focused?.closest('a')?.getAttribute('href'); remember(pane);dispose(record);record.node=node;record.stale=false;record.position={...position}; @@ -211,7 +212,7 @@ async function navigate(sceneId,sendWord=false) { const id=number(sceneId);if(!id)return; const manual=++manualGeneration;navigationRequest?.abort(); - setPosition({...scope,chapterId:null,sceneId:id},true);status.textContent=pinned?'Saved PlotDirector snapshot · manual selection':'Saved scene selected'; + setPosition({...scope,chapterId:null,sceneId:id});status.textContent=pinned?'Saved PlotDirector snapshot · manual selection':'Saved scene selected'; if(!sendWord||pinned||!scope.bookId)return; navigationRequest=new AbortController(); const token=document.querySelector('[data-word-sync-form] [name=__RequestVerificationToken]')?.value;