Merge remote-tracking branch 'origin/main' into claude/fix-228

# Conflicts:
#	CHANGELOG.md
This commit is contained in:
Frederic Jung 2026-10-31 07:37:43 +01:00
commit caa979a671
No known key found for this signature in database
14 changed files with 60 additions and 9 deletions

View file

@ -1,12 +1,14 @@
// Deliberately scan all exits for every flow, without byRank, local-city
// shortcuts or first-group selection. Stable sorting preserves E order on ties.
// Without Auto-TE, an exit whose shortest path from this POP is already full fits nothing, so it counts as
// unusable, like a full exit (#210).
module.exports = `
for(const pass of PASSES||[null])for(const rank of RANKS){
for(f of flows){
if(f.rem<=1e-6||(rank===0&&!f.cache)||(pass&&!pass(f)))continue;
Dv=SDi[f.ci];Pv=SPi[f.ci];PP=walked[f.ci]||(walked[f.ci]=[]);vis++;
const candidates=E.filter(e=>e.used<e.cap&&e.ok(f.n)&&
(TR?eff(e,f.n):base(e,f.n))===rank&&Dv[CIDX[e.city]]<Infinity)
(TR?eff(e,f.n):base(e,f.n))===rank&&Dv[CIDX[e.city]]<Infinity&&!gone(e))
.sort((a,b)=>(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||Dv[CIDX[a.city]]-Dv[CIDX[b.city]]);
for(let i=0;i<candidates.length&&f.rem>1e-6;){
let j=i+1;while(j<candidates.length&&(candidates[j].pref==='high')===(candidates[i].pref==='high')&&

View file

@ -1381,3 +1381,19 @@ test('#219 choosing one site again while the augment is on order keeps the LAG i
assert.equal(ev('S.pni[0].site'), 'b');
assert.deepEqual(errors, []);
});
test('#210 candidate exits on saturated shortest paths are skipped to avoid fallback churn', () => {
const { ev, errors } = load();
ev("ACT.start({});S.cash=1e8;UI.speed=0;for(const g of GOALS)S.done[g.id]=0;");
ev("ACT.buyTransit({city:'fra',net:'cog',tier:1});");
ev("ACT.buildPop({city:'par'});ACT.launchBB({city:'par'});");
ev("S.links.push({id:'x1',a:'fra',b:'par',kind:'wave',tier:0,km:450,mult:1,mo:1000,ready:0,cut:0});");
ev("compute();");
assert.ok(ev("R.load['x1'] >= 10 - 1e-6"), 'intercity wave is saturated');
assert.ok(ev("R.load['x1'] <= 10 + 1e-6"), 'and carries no more than it can');
// Skipping exits behind the full wave changes nothing: routing again gives the same answer.
const first = ev('JSON.stringify([R.served,R.citySrv,R.load])');
ev("compute();");
assert.equal(ev('JSON.stringify([R.served,R.citySrv,R.load])'), first);
assert.deepEqual(errors, []);
});

View file

@ -79,3 +79,25 @@ test('draft counts and quotes stay together when reopening a panel or using shor
assert.equal(field().value,'','empty in-progress entry survives a tick');
}finally{dom.window.close();}
});
test('#229 giving up a fiber puts its optics on the spares shelf, and so does decommissioning its POP',()=>{
const {ev,dom,errors}=load();try{
setup(ev);
// a leased IRU (not your own build) with mixed optics
ev("Object.assign(S.links[0],{own:false,ch:['zr4','zr4','tp16']});S.spares={zr4:1};compute()");
ev("ACT.rmLink({id:'fiber'})");assert.equal(ev('S.links.length'),1,'the first click only asks');
ev("ACT.rmLink({id:'fiber'})");assert.equal(ev('S.links.length'),0,'cancelled');
assert.equal(ev('S.spares.zr4'),3);assert.equal(ev('S.spares.tp16'),1);
assert.match(ev("S.log.map(e=>e.t).join(' | ')"),/3 optics went back on the spares shelf/);
// the next channel of that type uses a spare for free
ev("S.links.push({id:'f2',a:'fra',b:'ams',kind:'df',own:true,sys:'roadm',km:400,ch:[],ready:0,day:0,cut:0,mo:1});compute()");
const cash=ev('S.cash');ev("ACT.setChCount({id:'f2',o:'zr4',n:3})");assert.equal(ev('S.cash'),cash,'spares are used first');assert.equal(ev('S.spares.zr4'),0);
// decommissioning a POP returns the optics of every link it takes with it
ev("S.pops.lon={...S.pops.fra};S.links.push({id:'f3',a:'lon',b:'ams',kind:'df',own:true,sys:'roadm',km:400,ch:['tp16','tp16'],ready:0,day:0,cut:0,mo:1});compute()");
ev("decommission(['lon'])");
assert.equal(ev("S.links.some(l=>l.id==='f3')"),false);assert.equal(ev('S.spares.tp16'),3);
// a link without optics says nothing about spares
ev("S.log=[];S.links.push({id:'f4',a:'fra',b:'ams',kind:'df',own:true,sys:'roadm',km:400,ch:[],ready:0,day:0,cut:0,mo:1});compute();ACT.rmLink({id:'f4'});ACT.rmLink({id:'f4'})");
assert.doesNotMatch(ev("S.log.map(e=>e.t).join(' | ')"),/spares shelf/);
assert.deepEqual(errors,[]);
}finally{dom.window.close();}
});