28 lines
8.9 KiB
JavaScript
28 lines
8.9 KiB
JavaScript
// Opt-in Development-only canonical persistence acceptance. Requires an explicitly disposable identity and scope.
|
|
const {chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict');
|
|
(async()=>{assert(process.env.PD_CONTEXT_IDENTITY&&process.env.PD_CONTEXT_SCOPE,'Disposable Development inputs required');const who=JSON.parse(fs.readFileSync(process.env.PD_CONTEXT_IDENTITY)),s=JSON.parse(fs.readFileSync(process.env.PD_CONTEXT_SCOPE));assert.equal(who.Database,'PlotDirector_Development');assert.equal(who.UserID,s.user);assert(who.Email.startsWith('pwa-browser-'));assert(s.characters?.length===2);const browser=await chromium.launch();let step='login';try{
|
|
const pages=[],counts=[];
|
|
for(let i=0;i<2;i++){const c=await browser.newContext({viewport:{width:1280,height:900}}),p=await c.newPage();pages.push(p);await p.goto('https://dev.plotdirector.com/Account/Login');await p.locator('[name=Email]').fill(who.Email);await p.locator('[name=Password]').fill(who.Password);await Promise.all([p.waitForURL(u=>u.pathname!='/Account/Login'),p.locator('button[type=submit]').click()]);const count={hub:0,word:0,reads:0};counts.push(count);p.on('request',r=>{if(r.url().includes('/hubs/')&&r.url().includes('/negotiate'))count.hub++;if(r.url().includes('/Writing/Context/Navigate')||r.url().includes('/WriterWord/Navigate'))count.word++;if(r.url().includes('/Writing/Context/Tabs/'))count.reads++;});await p.goto(`https://dev.plotdirector.com/Writing/Context?projectId=${s.project}&bookId=${s.book}&sceneId=${s.scene}`);await p.waitForSelector('[data-context-tab-fragment]');await p.selectOption('[data-context-tab]','characters');await p.waitForSelector('[data-character-explorer]');await p.waitForFunction(()=>document.querySelector('[data-context-workspace]').contextController.connection?.state==='Connected');await p.evaluate(()=>{window.successes=0;const prior=window.PlotDirector.toast.success;window.PlotDirector.toast.success=(...a)=>{successes++;prior(...a);};});}
|
|
const [p,remote]=pages,id=s.characters[0],row=`[data-context-character="${id}"]`,stamp='Synthetic Context correction '+Date.now();
|
|
async function open(field){if(!await p.locator(row).evaluate(n=>n.open))await p.locator(row+' summary').click();await p.locator(row+` [data-context-edit="${field}"]`).click();await p.waitForSelector('[data-context-edit-form]');}
|
|
async function save(){await p.locator('[data-context-edit-form] [type=submit]').click();await p.waitForFunction(()=>!document.querySelector('[data-context-edit-dialog]').open);}
|
|
step='live canonical description and quiet remote refresh';await open('description');await p.locator('[name=Value]').fill(stamp);await save();await remote.waitForFunction(stamp=>document.querySelector('[data-character-explorer]').textContent.includes(stamp),stamp);assert.equal(await p.evaluate(()=>successes),1);assert.equal(await remote.evaluate(()=>successes),0);
|
|
step='canonical life-status persistence and lens separation';await open('life-status');const originalLife=await p.locator('[name=Value]').inputValue();await p.selectOption('[name=Value]','true');await save();await remote.waitForFunction(()=>document.querySelector('[data-character-explorer]').textContent.includes('Deceased'));
|
|
for(const lens of ['family','story']){const graph=await p.evaluate(async args=>{const response=await fetch('/Writing/Context/Relationships/'+(args.lens==='family'?'FamilyTree':'Graph')+'?'+new URLSearchParams(args));if(!response.ok)throw Error('Graph '+response.status);const data=await response.json();return data.graph||data;},{bookId:s.book,sceneId:s.scene,focusId:id,lens});assert.equal(graph.nodes.find(n=>n.id===id).isDeceased,lens==='family'?true:null);}
|
|
await open('life-status');assert.equal(await p.locator('[name=Value]').inputValue(),'true');await p.selectOption('[name=Value]',originalLife);await save();
|
|
step='cancel persists nothing';await open('description');assert.equal(await p.locator('[name=Value]').inputValue(),stamp);await p.locator('[name=Value]').fill('Discarded synthetic draft');p.once('dialog',d=>d.accept());await p.click('[data-context-edit-cancel]');await open('description');assert.equal(await p.locator('[name=Value]').inputValue(),stamp);await p.click('[data-context-edit-cancel]');
|
|
async function lookupIdentity(query){const details=p.locator('[data-established-names]');if(!await details.evaluate(n=>n.open))await details.locator('summary').first().click();await p.locator('[data-context-name-lookup] [name=search]').fill(query);await p.locator('[data-context-name-lookup] [type=submit]').click();await p.locator('[data-context-name-identities] [data-name-usage-fragment]').waitFor();await p.locator(`[data-context-name-identities] [data-name-identity="${id}"]`).click();await p.waitForSelector('[data-name-identity-fragment]');}
|
|
step='names alias add and persisted spelling';await p.selectOption('[data-context-tab]','names');await p.waitForSelector('[data-context-names]');await lookupIdentity('Synthetic Context person one');await p.locator(`[data-context-edit="alias-add"][data-character-id="${id}"]`).click();await p.waitForSelector('[data-context-edit-form]');const alias='Synthetic alias '+Date.now();await p.locator('[name=Value]').fill(alias);await save();await p.waitForSelector('[data-context-names]');await lookupIdentity(alias);assert.match(await p.locator('[data-name-identity-fragment]').innerText(),new RegExp(alias));
|
|
await p.waitForTimeout(350);await p.waitForFunction(()=>!document.querySelector('[data-context-pane="0"] [aria-busy="true"]'));await lookupIdentity(alias);
|
|
step='live inline validation retains failed draft';await p.locator(`[data-context-edit="name"][data-character-id="${id}"]`).click();await p.waitForSelector('[data-context-edit-form]');await p.locator('[name=Value]').fill('');await p.locator('[data-context-edit-form] [type=submit]').click();await p.waitForSelector('.validation-summary-errors');assert(await p.locator('[data-context-edit-dialog]').isVisible());assert.equal(await p.locator('[name=Value]').inputValue(),'');p.once('dialog',d=>d.accept());await p.click('[data-context-edit-cancel]');
|
|
if(process.env.PD_CONTEXT_RELATIONSHIPS==='1'){
|
|
step='live one-relationship create and correction';await p.selectOption('[data-context-tab]','relationships');await remote.selectOption('[data-context-tab]','relationships');await p.waitForSelector('[data-context-relationships]');await remote.waitForSelector('[data-context-relationships]');
|
|
await p.locator('[data-relationship-lens="story"]').click();await remote.locator('[data-relationship-lens="story"]').click();await p.waitForFunction(()=>document.querySelector('[data-relationship-caption]')?.textContent.includes('Later developments are excluded'));await remote.waitForFunction(()=>document.querySelector('[data-relationship-caption]')?.textContent.includes('Later developments are excluded'));
|
|
const existing=p.locator('[data-graph-edge]');if(await existing.count()===0){await p.locator('[data-relationship-add]').click();await p.waitForSelector('[data-context-edit-form]');await p.selectOption('[name=SourceID]',String(s.characters[0]));await p.selectOption('[name=TargetID]',String(s.characters[1]));const type=await p.locator('[name=TypeID] option').evaluateAll(ns=>ns.find(n=>n.value&&!n.textContent.includes('Family'))?.value);await p.selectOption('[name=TypeID]',type);const state=await p.locator('[name=StateID] option').evaluateAll(ns=>ns.find(n=>n.value)?.value);await p.selectOption('[name=StateID]',state);await p.locator('[name=Notes]').fill('Synthetic relationship evidence');await save();}
|
|
async function selectConnection(page){await page.locator(`[data-graph-node="${id}"]`).click();await page.locator('[data-relationship-details] details summary').click();await page.locator('[data-inspect-connection]').first().click();}
|
|
step='live relationship SVG ready';await p.waitForSelector('[data-graph-edge]',{state:'attached'});await remote.waitForSelector('[data-graph-edge]',{state:'attached'});await selectConnection(p);await selectConnection(remote);step='live relationship save modal';await p.locator('[data-relationship-details] [data-context-relationship-edit="scene"]').click();await p.waitForSelector('[data-context-edit-form]');const note='Synthetic relationship correction '+Date.now();await p.locator('[name=Notes]').fill(note);await save();step='live relationship remote update';await remote.waitForFunction(note=>document.querySelector('[data-context-relationships]').textContent.includes(note),note);assert.equal(await remote.evaluate(()=>successes),0);
|
|
|
|
}
|
|
assert(counts.every(c=>c.word===0&&c.hub===1));console.log('PASS Development canonical editing: focused persisted values, cancel/unsaved protection, alias add, failed inline name draft retained, one local success/quiet second authenticated session, one connection each, no Word navigation'+(process.env.PD_CONTEXT_RELATIONSHIPS==='1'?', relationship create/correct persisted through existing services':''));
|
|
} catch(e){console.error('FAILED '+step+': '+e.message);process.exitCode=1;}finally{await browser.close();}})();
|