const test=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path'); const M=require('./homeserver-model.js'); const base={mode:'direct',host:'home',bitrate:25,sessions:1,upload:100,hours:2}; test('home host uses one WAN upload in both direct and home relay paths',()=>{ const d=M.estimate(base),r=M.estimate({...base,mode:'home'});assert.ok(Math.abs(d.homeUp-27.5)<1e-8);assert.equal(d.homeDown,0);assert.equal(r.homeUp,d.homeUp);assert.equal(r.homeDown,0);assert.equal(r.relayInOut,d.homeUp*2);assert.ok(Math.abs(r.homeGB-24.75)<1e-8); }); test('two external peers consume home ingress and egress only when routed through home',()=>{ for(const mode of ['direct','vps']){const a=M.estimate({...base,host:'away',mode});assert.equal(a.homeUp,0);assert.equal(a.homeDown,0)} for(const mode of ['home','vpn']){const a=M.estimate({...base,host:'away',mode});assert.equal(a.homeUp,a.media);assert.equal(a.homeDown,a.media);assert.ok(Math.abs(a.homeGB-49.5)<1e-8)} }); test('VPS traffic is distinct from home traffic; saturation is not silently capped',()=>{ const a=M.estimate({...base,mode:'vps'});assert.ok(a.homeUp>0&&a.vpsGB>0);const b=M.estimate({...base,sessions:5,upload:10});assert.ok(b.ratio>1&&b.overBudget); }); test('domain examples reject URLs, ports and markup, preserving valid DNS names',()=>{ assert.equal(M.hostname(' Home.Example.Com '),'home.example.com');assert.equal(M.hostname('xn--example.com'),'xn--example.com'); for(const d of ['https://a.com','a.com:443','