notParsec / 문서전체 문서

생성 코드·템플릿

homeserver.test.cjs

design/homeserver.test.cjs

출처: 현재 작업 폴더 · 원문 다운로드

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','<script>.com','a..com','-a.com','a.com/','a.'.repeat(130)])assert.equal(M.hostname(d),null);
 for(const s of [{...base,mode:'unknown'},{...base,bitrate:NaN},{...base,sessions:1.5},{...base,upload:0}])assert.throws(()=>M.estimate(s));
});
test('standalone HTML has embedded logic, referenced controls and no external assets',()=>{
 const s=fs.readFileSync(path.join(__dirname,'homeserver-architecture.html'),'utf8');assert.ok(!s.includes('__HOME_MODEL__'));assert.ok(s.includes('공인 IP + UDP 포트포워딩'));assert.ok(!/<script[^>]+src=|<link[^>]+href=/i.test(s));
 const ids=[...s.matchAll(/\bid="([^"]+)"/g)].map(m=>m[1]);assert.equal(new Set(ids).size,ids.length);
 for(const m of s.matchAll(/href="#([^"]+)"/g))assert.ok(ids.includes(m[1]));
 for(const m of s.matchAll(/\$\('([^']+)'\)/g))assert.ok(ids.includes(m[1]),m[1]);
});

test('home explainer links concepts and server scope to the actual catalogue',()=>{
 const s=fs.readFileSync(path.join(__dirname,'homeserver-architecture.html'),'utf8');
 const p=JSON.parse(fs.readFileSync(path.join(__dirname,'plan-data.json'),'utf8'));
 for(const id of p.serverPlan.featureIds)assert.ok(s.includes(id),id);
 for(const target of ['id="concepts"','id="control-system"','Virtual Private Server','Virtual Private Network','notparsec-plan.html#server-system','CONTROL_SERVER.ko.md'])assert.ok(s.includes(target),target);
 assert.ok(!s.includes('기존 70개 기능'));assert.ok(s.includes('현재 '+p.features.length+'개 기능'));
});