const {chromium}=require('playwright'),fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict'); (async()=>{const browser=await chromium.launch();try{const page=await browser.newPage();const core={BookID:10,BookTitle:'Fixture',Stage:'Scanning Word',Message:'Reading paragraphs',PercentComplete:42,ResumeUrl:'/onboarding'}; async function boot(seed){await page.goto('about:blank');await page.setContent(``);await page.evaluate(seed=>{const strip=document.querySelector('[data-story-intelligence-global-strip]');strip.dataset.coreImport=JSON.stringify(seed);window.snapshot={coreImport:seed,books:[]};window.calls=[];window.handlers={};window.signalR={HubConnectionBuilder:class{withUrl(){return this;}withAutomaticReconnect(){return this;}build(){return{state:'Connected',on(n,f){handlers[n]=f;},onreconnected(){},onclose(){},start:async()=>{},invoke:async n=>{calls.push(n);return snapshot;}}}}};},seed);await page.addScriptTag({content:fs.readFileSync(path.join(__dirname,'../../PlotLine/wwwroot/js/story-intelligence-global-progress.js'),'utf8')});await page.waitForFunction(()=>calls.includes('WatchGlobalStoryIntelligenceProgress'));} await boot(core);const strip=page.locator('[data-story-intelligence-global-strip]'),link=page.locator('[data-story-intelligence-global-link]'),book=page.locator('[data-story-intelligence-global-action]');await page.waitForTimeout(50);assert.equal(await strip.isVisible(),true);assert.match(await strip.innerText(),/Scanning Word/);assert.equal(await link.getAttribute('href'),'/onboarding');assert.equal(await book.innerText(),'Book');assert.equal(await book.getAttribute('href'),'/Books/Details/10');assert.match(await page.locator('[data-story-intelligence-global-bar]').getAttribute('style'),/42%/); await boot(core);assert.equal(await strip.isVisible(),true);assert.equal(await link.getAttribute('href'),'/onboarding'); await page.evaluate(()=>handlers.StoryIntelligenceGlobalProgressChanged({coreImport:{bookID:10,bookTitle:'Fixture',stage:'Review chapters',message:'Capture saved',resumeUrl:'/onboarding/scan-review?previewId=123'},books:[]}));assert.match(await link.getAttribute('href'),/scan-review\?previewId=123/);assert.match(await strip.innerText(),/Review chapters/); await page.evaluate(()=>handlers.StoryIntelligenceGlobalProgressChanged({coreImport:null,books:[]}));assert.equal(await strip.isVisible(),false); await page.evaluate(()=>handlers.StoryIntelligenceGlobalProgressChanged({coreImport:null,books:[{bookID:10,projectID:9,bookTitle:'Fixture',status:'Pending',pendingRunCount:1,hasActiveRuns:true,totalExpectedScenes:4,completedScenes:0,updatedUtc:new Date().toISOString()}],hasActiveWork:true,activeBookCount:1,status:'Running',totalExpectedScenes:4,completedScenes:0}));assert.equal(await strip.isVisible(),true);assert.equal(await link.getAttribute('href'),'/Books/Details/10');assert.equal(await book.innerText(),'Book'); assert.equal(await page.evaluate(()=>calls.some(n=>/Start|Scan|Build/.test(n))),false);console.log('PASS existing global strip: Word scan visibility, recreated-page restore, exact review navigation, core completion hiding, independent optional AI Book link, and watch-only requests');}finally{await browser.close();}})().catch(e=>{console.error(e);process.exit(1);});