From 5ebb9f82e83288e0a0ba11d5b173b673074451ef Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Tue, 17 Nov 2026 23:49:38 +0000 Subject: [PATCH] Keep investigation recovery links scoped to in-page book changes --- PlotLine.Tests/Browser/investigation-companion.cjs | 6 ++++-- PlotLine/Views/Shared/_InvestigationCompanion.cshtml | 2 +- PlotLine/wwwroot/js/investigation-companion.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/PlotLine.Tests/Browser/investigation-companion.cjs b/PlotLine.Tests/Browser/investigation-companion.cjs index 53896d6d..c57eb183 100644 --- a/PlotLine.Tests/Browser/investigation-companion.cjs +++ b/PlotLine.Tests/Browser/investigation-companion.cjs @@ -28,8 +28,10 @@ const base=live?'https://dev.plotdirector.com':'http://127.0.0.1:5238',out=proce await expandRibbon();await p.getByRole('tab',{name:'Writer',exact:true}).click();await p.waitForURL(u=>/\/Writer(?:\/Index)?$/.test(u.pathname));await root.locator('#guidance-finding').waitFor();await expandRibbon();await p.locator('[data-app-back]').click();await p.waitForURL(live?/\/Timeline/:/\/Writer\/Review/);await root.locator('#guidance-finding').waitFor();assert(await first.locator('select').inputValue()==='Done');await snap('Ribbon-Back-retains-guidance'); await p.setViewportSize({width:800,height:1000});assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));assert((await root.locator('.pd-investigation-panel').boundingBox()).height<=551);await snap('Narrow-in-flow');await p.setViewportSize({width:1440,height:1000}); state=await c.storageState();await c.close();const reopened=await b.newContext({storageState:state,viewport:{width:1440,height:1000}});await reopened.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));const q=await reopened.newPage();await q.goto(`${base}/Writer/Explore?projectId=${w.project}&bookId=${w.book}`);await q.locator('#guidance-finding').waitFor();assert.equal(await q.locator('.pd-guidance-tool[data-capability=threads] select').inputValue(),'Done'); - await q.goto(`${base}/Writer/Explore?projectId=${w.project}&bookId=${w.otherBook}`);await q.waitForFunction(()=>document.querySelector('[data-guidance-content]')?.textContent.includes('No active investigation'));assert.equal(await q.locator('#guidance-finding').count(),0);assert.equal(await q.locator('[data-investigation-companion]').getAttribute('data-collapsed'),'true'); - await q.goto(`${base}/Writer/Explore?projectId=${w.project}&bookId=${w.book}`);await q.locator('#guidance-finding').waitFor(); + await q.goto(`${base}/Writer/Explore?projectId=${w.project}&bookId=${w.otherBook}`);await q.waitForFunction(()=>document.querySelector('[data-guidance-content]')?.textContent.includes('No active investigation'));assert.equal(await q.locator('#guidance-finding').count(),0);assert.equal(await q.locator('[data-investigation-companion]').getAttribute('data-collapsed'),'true');await q.locator('[data-guidance-expand]').click();const resume=await q.getByRole('link',{name:'Open saved investigations',exact:true}).getAttribute('href');assert.equal(new URL(resume).searchParams.get('bookId'),String(w.otherBook)); + // In-page book context changes use the same event as Calendar/At This Point and recheck server scope. + await q.evaluate(()=>document.dispatchEvent(new CustomEvent('plotdirector:book-context-changed',{detail:{bookId:0}})));await q.waitForFunction(()=>document.querySelector('[data-guidance-content]')?.textContent.includes('Choose a book'));await q.locator('[data-guidance-expand]').click();assert(!(new URL(await q.getByRole('link',{name:'Choose a book in Writer to resume an investigation'}).getAttribute('href'))).searchParams.has('bookId')); + await q.evaluate(book=>document.dispatchEvent(new CustomEvent('plotdirector:book-context-changed',{detail:{bookId:book}})),w.book);await q.locator('#guidance-finding').waitFor(); // Server-side failure paths retain the active guidance; forged IDs never expose it. const token=await q.locator('[data-guidance-token] [name=__RequestVerificationToken]').inputValue();const response=await q.request.post(base+'/InvestigationCompanion/Open',{form:{__RequestVerificationToken:token,bookId:w.book,id:w.investigation,finding:'disconnected',capability:'invented'}});assert.equal(response.status(),400); const wrong=await q.request.get(base+`/InvestigationCompanion/Evidence?bookId=${w.otherBook}&id=${w.investigation}&finding=disconnected`);assert.equal(wrong.status(),404); diff --git a/PlotLine/Views/Shared/_InvestigationCompanion.cshtml b/PlotLine/Views/Shared/_InvestigationCompanion.cshtml index f0c75913..3330c4b9 100644 --- a/PlotLine/Views/Shared/_InvestigationCompanion.cshtml +++ b/PlotLine/Views/Shared/_InvestigationCompanion.cshtml @@ -1,6 +1,6 @@ @model ApplicationNavigationViewModel