bend_puzzle/test/v4780-release-persistence-cursor-smoke-test.js
2026-08-01 16:06:14 +09:00

29 lines
3.9 KiB
JavaScript

'use strict';
const {assert,functionSource,app,css,html,read,vm,buildMeta}=require('./helpers/app-source');
const packageVersion=JSON.parse(read('package.json')).version;
assert(packageVersion===buildMeta.PACKAGE_VERSION&&buildMeta.APP_VERSION==='48.0','v47.84 canonical version marker is missing');
const bindBoard=functionSource('bindBoard');
assert(bindBoard.includes('const release=(paintCurrent=false)=>{')&&bindBoard.includes('cancelBoardDragFrame(b);clearDragRender(b);hidePickupHandleOverlay()'),'Pointer release does not synchronously stop the drag scheduler and remove the pickup overlay');
assert(functionSource('hidePickupHandleOverlay').includes("removeProperty('transform')"),'Pickup overlay retains its released compositor position');
const pickupDesign=functionSource('syncPickupHandleDesign'),pickupUpdate=functionSource('updatePickupHandleOverlay');
assert(pickupDesign.includes("classList.toggle('custom-cursor',Boolean(item))")&&pickupDesign.includes("classList.toggle('flag-cursor',Boolean(item?.flagAsset))")&&pickupDesign.includes('pickupHandleOverlay.replaceChildren(image)')&&pickupUpdate.includes('syncPickupHandleDesign()'),'Pickup overlay does not mirror the selected emoji/flag cursor');
assert(css.includes('#pickupHandleOverlay.custom-cursor.visible{display:grid}')&&css.includes('#pickupHandleOverlay.custom-cursor.flag-cursor img'),'Custom cursor pickup overlay CSS is missing');
assert(functionSource('syncCursorAppearance').includes('syncPickupHandleDesign()'),'Changing cursor style does not refresh the pickup appearance');
const merge=functionSource('mergeSnapshotIntoData');
assert(merge.includes('authoritativeCompatibleStateIds=authoritativeWorld?new Set():null')&&merge.includes('retainLocalSolve=compatible&&current?.solved===true&&incoming?.solved!==true')&&merge.includes('retainClaimedPending=compatible')&&merge.includes("if(retainLocalSolve){noteCloudRow('state',id);merged=deepClone(current)}")&&merge.includes('else{clearSharedWorldJournalRow')&&!merge.includes('merged=compatible?mergeBoardStates(current,incoming):deepClone(incoming)'),'Authoritative pull can still downgrade a compatible local clear, erase a claimant retry, or merge stale unfinished paths');
const completion=functionSource('checkSolvedAndExpand');
const cloudFailure=completion.slice(completion.indexOf('let published=false'),completion.indexOf('const immediateBoard='));
assert(completion.includes('writeDirtyRecoveryJournal();')&&cloudFailure.includes('for(let attempt=0;attempt<3&&!published;attempt++)')&&cloudFailure.includes('data.states[b.id]=previous.state')&&cloudFailure.includes('await persistNow({skipCloud:true})'),'Completion is not verified by the shared server or is left locally solved after publication failure');
const overlay={dataset:{},classList:{values:new Set(),toggle(name,on){on?this.values.add(name):this.values.delete(name)}},replaceChildren(node){this.child=node;this.textContent=''},textContent:'',style:{}};
const cursorItems=new Map([['emoji-test',{cursorStyle:'emoji-test',cursorEmoji:'🙂'}]]);
const context={pickupHandleOverlay:overlay,data:{cursorStyle:'emoji-test'},cursorModel:{item:style=>cursorItems.get(style)||null},document:{createElement(){return{src:'',alt:'',draggable:true}}}};
vm.createContext(context);vm.runInContext(`${functionSource('activeCustomCursorItem')}\n${pickupDesign}\nthis.syncPickupHandleDesign=syncPickupHandleDesign;`,context);
assert(context.syncPickupHandleDesign()===true&&overlay.textContent==='🙂'&&overlay.classList.values.has('custom-cursor')&&!overlay.classList.values.has('flag-cursor'),'Emoji cursor was not applied to the pickup overlay');
context.data.cursorStyle='flag-test';cursorItems.set('flag-test',{cursorStyle:'flag-test',flagAsset:'flag.svg'});context.syncPickupHandleDesign();
assert(overlay.child?.src==='flag.svg'&&overlay.classList.values.has('flag-cursor'),'Flag cursor was not applied to the pickup overlay');
console.log('v47.84 pickup release, durable completion, and cursor-design regression test passed');