assert(made>=4,`Full expansion generated only ${made} fields`);assert(remaining.length===0,`Full expansion left ${remaining.length} frontiers`);assert(context.data.states.B0.expanded===true,'Origin was not marked fully expanded');
assert(matching,`Origin gate ${gate.join(',')} generated a board without the matching opposite gate`);
assert(!(neighbor.sealedSides||[]).includes(context.OPP[gate[2]]),`Matching gate for ${gate.join(',')} was sealed`);
}
assert(context.logic.missingGateConnections(origin).length===0,'Origin was marked expanded without an actual facing board for every gate');
for(constmetaofObject.values(context.data.metas).filter(meta=>meta.id!=='B0')){constrange=AppLogic.sectionCountRange(meta.level);assert(meta.chunks.length>=range.min&&meta.chunks.length<=range.max,`${meta.id}: level ${meta.level} has ${meta.chunks.length} sections outside ${range.min}-${range.max}`);assert(context.logic.viableExpansionExists(meta),`${meta.id}: newly generated board has no viable future expansion placement`)}
assert(elapsed<8000,`Origin expansion took ${elapsed} ms`);
assert(calls.refresh===1&&calls.render===1&&calls.hud===1&&calls.save===1&&calls.paint===1,`Expansion was not committed once: ${JSON.stringify(calls)}`);
assert(branchMade>0,`${branch.id}: solved child did not generate a branch`);constbranchRemaining=context.logic.gateFrontierCandidates(branch);assert(context.data.states[branch.id].expanded===(branchRemaining.length===0),`${branch.id}: expanded flag does not match remaining gate targets`);assert(Object.keys(context.data.metas).some(id=>!beforeBranchIds.has(id)),`${branch.id}: no adjacent field was added`);
for(constmetaofObject.values(context.data.metas))if(!context.metaState(meta.id).solved)assert(context.logic.viableExpansionExists(meta),`${meta.id}: branch expansion stranded an unsolved board`);
assert(branchElapsed<15000,`${branch.id}: branch expansion took ${branchElapsed} ms`);
assert(candidate,`Expansion chain had no candidate at step ${step}`);chained+=generated;if(context.metaState(candidate.id).expanded)assert(context.logic.missingGateConnections(candidate).length===0,`${candidate.id}: expanded despite a missing facing gate at step ${step}`);
for(constmetaofObject.values(context.data.metas))if(!context.metaState(meta.id).solved)assert(context.logic.viableExpansionExists(meta),`${meta.id}: expansion chain created a non-expandable board`);
assert(child,'Level-6 normal frontier could not generate a board');constrange=AppLogic.sectionCountRange(child.targetLevel);assert(child.chunks.length>=range.min&&child.chunks.length<=range.max,'Higher-level board violates its authoritative regional section range');assert(child.chunks.length>1,'Higher-level multi-section generation still depends on a retired special mode');assert(!('labyrinth'inchild)&&child.anomaly!=='giant','Retired special-board metadata was generated');assert(context.logic.viableExpansionExists(child),'Higher-level child was generated as a dead end');
assert(fallbackChild===null,'Invalid single-section fallback was forced into a level requiring multiple sections');assert(Object.keys(context.data.metas).length===1&&context.data.metas.F===fallbackSource,'Rejected fallback mutated the world');assert(context.data.nextId===700,'Rejected fallback consumed a board id');
constmultiMade=awaitcontext.logic.expandMetaNow(multiSource);assert(multiMade>0,'Clearing a multi-section board did not unlock any new board');assert(context.unsolvedBoardCount()>0,'Multi-section clear left no playable board');if(context.metaState('M').expanded)assert(context.logic.missingGateConnections(multiSource).length===0,'Multi-section board was marked expanded with missing gate neighbors');
assert(requirements.some(req=>req.metaId==='R'&&req.gateIndex===eastGateIndex),'Proposed placement did not capture the source gate requirement');assert(context.logic.puzzleSupportsConnectionRequirements(validChild,targetX,targetY,requirements),'A deterministic matching child was rejected');assert(!context.logic.puzzleSupportsConnectionRequirements(invalidChild,targetX,targetY,requirements),'A child without the facing gate was accepted');
assert(regenerated,'Whole-board regeneration did not recover after a rejected completed candidate');assert(regenOptions.length>=2&®enSpecialSeeds.length>=2,'Rejected board did not rerun routing and special-cell generation');assert(regenOptions[0]?.portSeed==null&&Number.isInteger(regenOptions[1]?.portSeed),'Unconfirmed gate positions were not rerolled after rejection');assert(regenSpecialSeeds[0]!==regenSpecialSeeds[1],'Special-cell seed was not rerolled after rejection');
context.data.metas.U={id:'U',x:200,y:200,chunks:[[0,0]],seed:9,puzzle:starter,sealedSides:[],rev:1};context.data.states.U={solved:false,expanded:false,paths:[],specialProgress:{crossings:[]},rev:1};context.data.metas.N={id:'N',x:199,y:200,chunks:[[0,0]],seed:10,puzzle:starter,sealedSides:[],rev:1};context.data.states.N={solved:true,expanded:true,paths:[],specialProgress:{crossings:[]},rev:1};context.data.metas.S2={id:'S2',x:200,y:201,chunks:[[0,0]],seed:11,puzzle:starter,sealedSides:[],rev:1};context.data.states.S2={solved:true,expanded:true,paths:[],specialProgress:{crossings:[]},rev:1};context.data.metas.W2={id:'W2',x:200,y:199,chunks:[[0,0]],seed:12,puzzle:starter,sealedSides:[],rev:1};context.data.states.W2={solved:true,expanded:true,paths:[],specialProgress:{crossings:[]},rev:1};context.rebuildOccupancy();assert(context.logic.openUnitFrontiers(context.data.metas.U).length===1,'Synthetic board does not have exactly one remaining frontier');assert(!context.logic.placementPreservesUnsolvedFrontiers(201,200,[[0,0]]),"Placement was allowed to consume an unsolved board's final frontier");
assert(closedChild&&closedChild.chunks.length===1&&context.occupancy.get(context.key2(closedX,closedY))===closedChild.id,'The enclosed field gap was not repaired with a generated puzzle');
assert(ungatedChild&&ungatedChild.chunks.length===1&&ungatedChild.sealedSides.includes('N')&&ungatedChild.sealedSides.includes('S')&&ungatedChild.sealedSides.includes('W')&&ungatedChild.sealedSides.includes('E'),`Ungated enclosed gap was not generated as a sealed puzzle: ${JSON.stringify(ungatedChild&&{chunks:ungatedChild.chunks,sealedSides:ungatedChild.sealedSides})}`);
console.log(`Expansion integration passed: ${made} origin fields in ${elapsed} ms; ${branchMade} branch fields; ${chained} chained fields; level ${child.level} normal board has ${child.chunks.length} sections`);