// Generic capability qualification. Timeline-specific acceptance belongs to task 52. const assert=require('node:assert/strict'),fs=require('node:fs'); const {open,target}=require('./dev-acceptance.cjs'); let stage='session',session,passed=false,failure;const checks=[]; (async()=>{try{ assert.match(fs.readFileSync('/proc/self/status','utf8'),/^NoNewPrivs:\s+1$/m);checks.push('native-sandbox-no-new-privileges'); for(const file of ['/etc/plotdirector/plotdirector.env','/home/nick/.local/share/plotdirector-development/signing/private.pem']){let fd;try{fd=fs.openSync(file,'r');}catch(error){assert(['EACCES','EPERM','ENOENT'].includes(error.code));continue;}fs.closeSync(fd);throw new Error('Protected operational file unexpectedly readable');} checks.push('runtime-configuration-and-signing-key-unreadable'); session=await open();checks.push('normal-authentication'); await session.goto('/Projects');assert.equal(await session.page.locator('.project-card').count(),0);checks.push('isolated-account-empty-workspace'); const sentinel=JSON.parse(process.env.PD_BROWSER_SENTINEL_IDS||'{}');assert(Number.isSafeInteger(sentinel.project)&&Number.isSafeInteger(sentinel.book),'operator-created disposable isolation sentinel required'); for(const route of ['/Projects/Details/'+sentinel.project,'/Books/Edit/'+sentinel.book])assert.equal((await session.goto(route)).status(),404); await session.goto('/Projects'); const denied=await session.page.evaluate(async id=>{const token=document.querySelector('[name=__RequestVerificationToken]').value;return (await fetch('/Projects/Archive/'+id,{method:'POST',body:new URLSearchParams({__RequestVerificationToken:token})})).status;},sentinel.project); assert.equal(denied,404);checks.push('unrelated-disposable-project-read-and-write-denied'); const admin=await session.goto('/Admin');assert(admin.status()===403||new URL(session.page.url()).pathname==='/Account/AccessDenied');checks.push('ordinary-account-not-administrator'); assert.throws(()=>target('https://app.plotdirector.com/Projects')); await session.goto('/Projects');const before=session.blockedExternal(); assert(await session.page.evaluate(async()=>{try{await fetch('https://app.plotdirector.com/Account/Login',{method:'POST',body:'synthetic-boundary-probe'});return false;}catch{return true;}})); assert(session.blockedExternal()>before);checks.push('production-request-aborted-before-network'); stage='create';const project=await session.project(); stage='create-book';const book=await session.create('Books','?projectId='+project,{BookTitle:'Disposable acceptance book',BookNumber:1}); stage='create-chapter';const chapter=await session.create('Chapters','?bookId='+book,{ChapterTitle:'Disposable chapter',ChapterNumber:1}); stage='create-character';await session.create('Characters','?projectId='+project,{CharacterName:'Disposable character'},async page=>{const sex=page.locator('[name=CustomSex]');if(await sex.isEnabled()&&await sex.getAttribute('required')!==null)await sex.fill('Unspecified');}); stage='create-location';await session.create('Locations','?projectId='+project,{LocationName:'Disposable location'}); checks.push('ordinary-project-book-chapter-character-location-forms'); stage='save';await session.goto('/Books/Edit/'+book); const title='Persisted acceptance '+session.runId; await session.page.locator('[name=BookTitle]').fill(title); await Promise.all([session.page.waitForURL('**/Books/Details/'+book),session.page.locator('main form.pd-record-form button[type=submit]').filter({hasText:/Save/}).evaluate(button=>button.form.requestSubmit(button))]); await session.goto('/Books/Edit/'+book);await session.page.reload();assert.equal(await session.page.inputValue('[name=BookTitle]'),title);checks.push('save-and-reload-persistence'); stage='fresh-session';await session.close();session=await open();await session.goto('/Books/Edit/'+book);assert.equal(await session.page.inputValue('[name=BookTitle]'),title);checks.push('fresh-authenticated-browser-confirms-server-persistence'); stage='cleanup';await session.cleanup();await session.goto('/Projects');assert.equal(await session.page.locator('.project-card').count(),0);checks.push('owned-fixture-archived-permanently-deleted-and-absence-verified'); passed=true; }catch(error){failure=error.message.startsWith('fixture-create:')?JSON.parse(error.message.slice('fixture-create:'.length)):{type:error.name};throw new Error('Capability check failed');}finally{ if(session){try{await session.cleanup();}catch{passed=false;checks.push('cleanup-requires-resume');}await session.close();} const result={passed,stage,failure,checks,credentialsLogged:false,productionContacted:false,timelineAcceptancePerformed:false}; if(process.env.PD_BROWSER_EVIDENCE)fs.writeFileSync(process.env.PD_BROWSER_EVIDENCE,JSON.stringify(result,null,2)+'\n',{mode:0o600}); console.log(JSON.stringify(result)); } })().catch(()=>{console.error('Development capability probe failed at '+stage+'; inspect fixture state and use cleanup recovery. No credentials logged.');process.exitCode=1;});