Clear the open code scanning alerts
- auto-release.yml: the by-hand test run passes github.sha (what it got anyway) instead of an output that also reads workflow_run.head_sha, so CI never checks out a ref a workflow_run handed over in a job that uses caches (cache poisoning, 7 alerts in ci.yml). - tests/harness.js: the script splitter also matches end tags like </SCRIPT > (bad HTML filtering regexp). - Tests paste the fixture saves into the page with lit(), which escapes what could end a script or a string, instead of plain JSON.stringify (improper code sanitization).
This commit is contained in:
parent
f00bc733d0
commit
4630ba99af
9 changed files with 18 additions and 11 deletions
5
.github/workflows/auto-release.yml
vendored
5
.github/workflows/auto-release.yml
vendored
|
|
@ -70,13 +70,14 @@ jobs:
|
||||||
case "$ver" in *-*) echo "pre=true" >> "$GITHUB_OUTPUT";; *) echo "pre=false" >> "$GITHUB_OUTPUT";; esac
|
case "$ver" in *-*) echo "pre=true" >> "$GITHUB_OUTPUT";; *) echo "pre=false" >> "$GITHUB_OUTPUT";; esac
|
||||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
# Only when started by hand: after a push, CI has already tested this commit.
|
# Only when started by hand: after a push, CI has already tested this commit. By hand the commit is main as it is
|
||||||
|
# (github.sha, what check.outputs.sha is then), named directly so CI never checks out a ref a workflow_run handed over.
|
||||||
tests:
|
tests:
|
||||||
needs: check
|
needs: check
|
||||||
if: needs.check.outputs.skip == 'false' && github.event_name == 'workflow_dispatch'
|
if: needs.check.outputs.skip == 'false' && github.event_name == 'workflow_dispatch'
|
||||||
uses: ./.github/workflows/ci.yml
|
uses: ./.github/workflows/ci.yml
|
||||||
with:
|
with:
|
||||||
ref: ${{ needs.check.outputs.sha }}
|
ref: ${{ github.sha }}
|
||||||
|
|
||||||
release:
|
release:
|
||||||
needs: [check, tests]
|
needs: [check, tests]
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,13 @@ const assert = require('node:assert/strict');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { load } = require('./harness');
|
const { load } = require('./harness');
|
||||||
|
const { lit } = require('../scripts/lib/js-literal');
|
||||||
|
|
||||||
const BIG = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
const BIG = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
||||||
// The big network with an intern running every order, a failure and an event due soon, its circuits on scenic
|
// The big network with an intern running every order, a failure and an event due soon, its circuits on scenic
|
||||||
// routes, which read yesterday's R.efg, and renewal haggles the sales desk answers (slRenRun() routes after them). Ids come from Date.now(),
|
// routes, which read yesterday's R.efg, and renewal haggles the sales desk answers (slRenRun() routes after them). Ids come from Date.now(),
|
||||||
// so the clock stands still in every page.
|
// so the clock stands still in every page.
|
||||||
const SETUP = `Date.now=()=>1.7e12;S=migrate(JSON.parse(${JSON.stringify(BIG)}));UI.started=true;UI.pitched=true;UI.speed=0;closeModal();autoPause=()=>false;
|
const SETUP = `Date.now=()=>1.7e12;S=migrate(JSON.parse(${lit(BIG)}));UI.started=true;UI.pitched=true;UI.speed=0;closeModal();autoPause=()=>false;
|
||||||
S.cash=1e9;ACT.salesHire({id:'eng'});closeModal();S.slAuto.on=true;S.slAuto.ren=true;window.__ren=0;{const f=slRenOne;slRenOne=function(){__ren++;return f.apply(this,arguments);};}
|
S.cash=1e9;ACT.salesHire({id:'eng'});closeModal();S.slAuto.on=true;S.slAuto.ren=true;window.__ren=0;{const f=slRenOne;slRenOne=function(){__ren++;return f.apply(this,arguments);};}
|
||||||
for(const b of S.biz.filter(b=>clOn(b)&&!BIZ_T[b.type].fiber).slice(0,20)){b.te=S.day+28;b.hag={rate:Math.round(b.rate*0.7),until:S.day+28};}
|
for(const b of S.biz.filter(b=>clOn(b)&&!BIZ_T[b.type].fiber).slice(0,20)){b.te=S.day+28;b.hag={rate:Math.round(b.rate*0.7),until:S.day+28};}
|
||||||
S.ops.intern='tracy';S.ops.hired=S.day;for(const k in S.ops.on)S.ops.on[k]=true;S.ops.floor=0;for(const k in S.ops.cap)S.ops.cap[k]=0;
|
S.ops.intern='tracy';S.ops.hired=S.day;for(const k in S.ops.on)S.ops.on[k]=true;S.ops.floor=0;for(const k in S.ops.cap)S.ops.cap[k]=0;
|
||||||
|
|
@ -110,7 +111,7 @@ test('an action while the worker routes stands; another network loaded mid-day g
|
||||||
// A new game while a day is in flight: the old day's steps never touch it.
|
// A new game while a day is in flight: the old day's steps never touch it.
|
||||||
p.ev('rwDay()');
|
p.ev('rwDay()');
|
||||||
const day = p.ev('S.day');
|
const day = p.ev('S.day');
|
||||||
p.ev(`window.__old=S;S=migrate(JSON.parse(${JSON.stringify(BIG)}));compute();`);
|
p.ev(`window.__old=S;S=migrate(JSON.parse(${lit(BIG)}));compute();`);
|
||||||
const fresh = p.ev('JSON.stringify(S.hist)');
|
const fresh = p.ev('JSON.stringify(S.hist)');
|
||||||
p.pump();
|
p.pump();
|
||||||
assert.equal(p.ev('JSON.stringify(S.hist)'), fresh);
|
assert.equal(p.ev('JSON.stringify(S.hist)'), fresh);
|
||||||
|
|
|
||||||
|
|
@ -654,7 +654,7 @@ test('O7: a fresh Tier 1 cannot afford a full Shortcrust in its first year', ()
|
||||||
// most the Ex-Im Pie Bank lends a rocket company on top.
|
// most the Ex-Im Pie Bank lends a rocket company on top.
|
||||||
const g = load();
|
const g = load();
|
||||||
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
||||||
g.ev(`S=migrate(JSON.parse(${JSON.stringify(save)}));compute()`);
|
g.ev(`S=migrate(JSON.parse(${lit(save)}));compute()`);
|
||||||
const rev = g.ev('R.revMo'), loan = g.ev('Math.max(...Object.values(BANKS).map(b=>b.amt[1]))') * rev + g.ev('pieEximCap()'), cash = Math.max(0, g.ev('S.cash'));
|
const rev = g.ev('R.revMo'), loan = g.ev('Math.max(...Object.values(BANKS).map(b=>b.amt[1]))') * rev + g.ev('pieEximCap()'), cash = Math.max(0, g.ev('S.cash'));
|
||||||
const year = 12 * rev + loan + Math.min(cash, 12 * rev);
|
const year = 12 * rev + loan + Math.min(cash, 12 * rev);
|
||||||
const full = g.ev("pieFullCost('short')");
|
const full = g.ev("pieFullCost('short')");
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ function split(html) {
|
||||||
let s = SPLIT.get(html);
|
let s = SPLIT.get(html);
|
||||||
if (s) return s;
|
if (s) return s;
|
||||||
const code = [];
|
const code = [];
|
||||||
const shell = html.replace(/<script>([\s\S]*?)<\/script>/g, (m, src) => {
|
const shell = html.replace(/<script>([\s\S]*?)<\/script\b[^>]*>/gi, (m, src) => {
|
||||||
code.push(new vm.Script(src, { filename: `page-script-${code.length}.js` }));
|
code.push(new vm.Script(src, { filename: `page-script-${code.length}.js` }));
|
||||||
return '<script></script>';
|
return '<script></script>';
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@ const assert = require('node:assert/strict');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { load } = require('./harness');
|
const { load } = require('./harness');
|
||||||
|
const { lit } = require('../scripts/lib/js-literal');
|
||||||
|
|
||||||
const BIG = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
const BIG = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
||||||
|
|
||||||
test('land islands answer "a path without subsea" as walking the links does', () => {
|
test('land islands answer "a path without subsea" as walking the links does', () => {
|
||||||
const { ev, errors } = load({ seed: 3 });
|
const { ev, errors } = load({ seed: 3 });
|
||||||
ev(`S=migrate(JSON.parse(${JSON.stringify(BIG)}));UI.started=true;closeModal();compute();`);
|
ev(`S=migrate(JSON.parse(${lit(BIG)}));UI.started=true;closeModal();compute();`);
|
||||||
const cmp = () => JSON.parse(ev(`(()=>{const cs=Object.keys(S.pops).concat(['sin','nyc','lon',null,undefined]);let n=0,yes=0;const bad=[];
|
const cmp = () => JSON.parse(ev(`(()=>{const cs=Object.keys(S.pops).concat(['sin','nyc','lon',null,undefined]);let n=0,yes=0;const bad=[];
|
||||||
for(const a of cs.slice(0,60))for(const b of cs){if(!a)continue;TERR=null;const w=terrestrialPath(a,b);TERR={S,gen:RW.gen,m:null};const i=terrestrialPath(a,b);TERR=null;
|
for(const a of cs.slice(0,60))for(const b of cs){if(!a)continue;TERR=null;const w=terrestrialPath(a,b);TERR={S,gen:RW.gen,m:null};const i=terrestrialPath(a,b);TERR=null;
|
||||||
n++;if(w)yes++;if(w!==i)bad.push(a+'-'+b);}return JSON.stringify({n,yes,bad:bad.slice(0,5)});})()`));
|
n++;if(w)yes++;if(w!==i)bad.push(a+'-'+b);}return JSON.stringify({n,yes,bad:bad.slice(0,5)});})()`));
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ const assert = require('node:assert/strict');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { load } = require('./harness');
|
const { load } = require('./harness');
|
||||||
|
const { lit } = require('../scripts/lib/js-literal');
|
||||||
|
|
||||||
// A backbone London – New York – Auckland with transit in London and New York, full dishes with landing rights there, a
|
// A backbone London – New York – Auckland with transit in London and New York, full dishes with landing rights there, a
|
||||||
// full lasered Shortcrust, and Pitcairn (Adamstown): a POP of its own with broadband, no cable, and a dish.
|
// full lasered Shortcrust, and Pitcairn (Adamstown): a POP of its own with broadband, no cable, and a dish.
|
||||||
|
|
@ -230,7 +231,7 @@ test('the traceroute to and from a cut-off POP shows the orbit hops', () => {
|
||||||
test('saves without pies, and pie saves whose POPs are all connected, route as before', () => {
|
test('saves without pies, and pie saves whose POPs are all connected, route as before', () => {
|
||||||
const { ev, errors } = load();
|
const { ev, errors } = load();
|
||||||
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
||||||
ev(`S=migrate(JSON.parse(${JSON.stringify(save)}));compute()`);
|
ev(`S=migrate(JSON.parse(${lit(save)}));compute()`);
|
||||||
assert.equal(ev('S.pie'), null);
|
assert.equal(ev('S.pie'), null);
|
||||||
const out = () => ev("JSON.stringify([R.served,R.demand,R.egT,R.load,R.l2,R.l2lat,R.citySrv])");
|
const out = () => ev("JSON.stringify([R.served,R.demand,R.egT,R.load,R.l2,R.l2lat,R.citySrv])");
|
||||||
const a = out();
|
const a = out();
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ const assert = require('node:assert/strict');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { load } = require('./harness');
|
const { load } = require('./harness');
|
||||||
|
const { lit } = require('../scripts/lib/js-literal');
|
||||||
|
|
||||||
const YEARS = +(process.env.PIE_BALANCE_YEARS || 0);
|
const YEARS = +(process.env.PIE_BALANCE_YEARS || 0);
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@ const YEARS = +(process.env.PIE_BALANCE_YEARS || 0);
|
||||||
function sim(days, stop = false, seed = 7, gov = false) {
|
function sim(days, stop = false, seed = 7, gov = false) {
|
||||||
const g = load({ seed });
|
const g = load({ seed });
|
||||||
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
||||||
g.ev(`S=migrate(JSON.parse(${JSON.stringify(save)}));S.pieV=1;UI.started=true;UI.pitched=true;UI.speed=0;S.nextFail=1e9;S.nextEvent=1e9;
|
g.ev(`S=migrate(JSON.parse(${lit(save)}));S.pieV=1;UI.started=true;UI.pitched=true;UI.speed=0;S.nextFail=1e9;S.nextEvent=1e9;
|
||||||
isTier1=()=>true;after=()=>{};pieModal=()=>{};compute();pieInit();UI.pieLas=true;ACT.pieFound();ACT.pieFactory();ACT.pieRd({k:'reuse'});
|
isTier1=()=>true;after=()=>{};pieModal=()=>{};compute();pieInit();UI.pieLas=true;ACT.pieFound();ACT.pieFactory();ACT.pieRd({k:'reuse'});
|
||||||
for(const c of Object.keys(S.pops).filter(c=>pieCoast(c)&&piePadOk(c,'short')).sort((a,b)=>Math.abs(CITY[a].lat)-Math.abs(CITY[b].lat)).slice(0,2))ACT.piePad({city:c});
|
for(const c of Object.keys(S.pops).filter(c=>pieCoast(c)&&piePadOk(c,'short')).sort((a,b)=>Math.abs(CITY[a].lat)-Math.abs(CITY[b].lat)).slice(0,2))ACT.piePad({city:c});
|
||||||
window.__site=()=>{const ds=S.pie.dishes,lic=c=>pieLicOk(CITY[c].cc)?0:pieLicPrice(CITY[c].cc);
|
window.__site=()=>{const ds=S.pie.dishes,lic=c=>pieLicOk(CITY[c].cc)?0:pieLicPrice(CITY[c].cc);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ const assert = require('node:assert/strict');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { load } = require('./harness');
|
const { load } = require('./harness');
|
||||||
|
const { lit } = require('../scripts/lib/js-literal');
|
||||||
|
|
||||||
// A sandbox with London and New York joined by a transatlantic wave, Frankfurt 640 km from London, a company, and a
|
// A sandbox with London and New York joined by a transatlantic wave, Frankfurt 640 km from London, a company, and a
|
||||||
// 16-antenna dish with landing rights at each POP.
|
// 16-antenna dish with landing rights at each POP.
|
||||||
|
|
@ -159,7 +160,7 @@ test('spats: data stays home, and not over my airspace', () => {
|
||||||
test('saves without pies route identically, and pay nothing for orbit', () => {
|
test('saves without pies route identically, and pay nothing for orbit', () => {
|
||||||
const { ev, errors } = load();
|
const { ev, errors } = load();
|
||||||
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
||||||
ev(`S=migrate(JSON.parse(${JSON.stringify(save)}));compute()`);
|
ev(`S=migrate(JSON.parse(${lit(save)}));compute()`);
|
||||||
assert.equal(ev('S.pie'), null);
|
assert.equal(ev('S.pie'), null);
|
||||||
const out = () => ev("JSON.stringify([R.served,R.demand,R.revMo,R.egT,R.load,R.l2,R.l2lat,R.rev])");
|
const out = () => ev("JSON.stringify([R.served,R.demand,R.revMo,R.egT,R.load,R.l2,R.l2lat,R.rev])");
|
||||||
const a = out();
|
const a = out();
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ const assert = require('node:assert/strict');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { load } = require('./harness');
|
const { load } = require('./harness');
|
||||||
|
const { lit } = require('../scripts/lib/js-literal');
|
||||||
|
|
||||||
// London, New York and Frankfurt on one backbone, a company, 16-antenna dishes with landing rights at each.
|
// London, New York and Frankfurt on one backbone, a company, 16-antenna dishes with landing rights at each.
|
||||||
const world = (ev, opt = {}) => {
|
const world = (ev, opt = {}) => {
|
||||||
|
|
@ -195,7 +196,7 @@ test('the traceroute shows a circuit through orbit hop by hop', () => {
|
||||||
test('saves without pies: no traffic data, the same routing, and an untouched map', () => {
|
test('saves without pies: no traffic data, the same routing, and an untouched map', () => {
|
||||||
const { ev, errors } = load();
|
const { ev, errors } = load();
|
||||||
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
||||||
ev(`S=migrate(JSON.parse(${JSON.stringify(save)}));compute()`);
|
ev(`S=migrate(JSON.parse(${lit(save)}));compute()`);
|
||||||
assert.equal(ev('R.pie===undefined'), true);
|
assert.equal(ev('R.pie===undefined'), true);
|
||||||
assert.equal(ev("trSkyList().length"), 0);
|
assert.equal(ev("trSkyList().length"), 0);
|
||||||
assert.equal(ev("pieFiberMs({k:'c',id:'x'})"), Infinity);
|
assert.equal(ev("pieFiberMs({k:'c',id:'x'})"), Infinity);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue