diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index 6332c25..765105b 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -70,13 +70,14 @@ jobs: case "$ver" in *-*) echo "pre=true" >> "$GITHUB_OUTPUT";; *) echo "pre=false" >> "$GITHUB_OUTPUT";; esac 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: needs: check if: needs.check.outputs.skip == 'false' && github.event_name == 'workflow_dispatch' uses: ./.github/workflows/ci.yml with: - ref: ${{ needs.check.outputs.sha }} + ref: ${{ github.sha }} release: needs: [check, tests] diff --git a/tests/day-steps.test.js b/tests/day-steps.test.js index b9ad08b..027b065 100644 --- a/tests/day-steps.test.js +++ b/tests/day-steps.test.js @@ -9,12 +9,13 @@ const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const { load } = require('./harness'); +const { lit } = require('../scripts/lib/js-literal'); 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 // 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. -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);};} 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; @@ -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. p.ev('rwDay()'); 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)'); p.pump(); assert.equal(p.ev('JSON.stringify(S.hist)'), fresh); diff --git a/tests/gameplay-rules.test.js b/tests/gameplay-rules.test.js index 38795de..44414ca 100644 --- a/tests/gameplay-rules.test.js +++ b/tests/gameplay-rules.test.js @@ -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. const g = load(); 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 year = 12 * rev + loan + Math.min(cash, 12 * rev); const full = g.ev("pieFullCost('short')"); diff --git a/tests/harness.js b/tests/harness.js index 2e5c0a2..f03638e 100644 --- a/tests/harness.js +++ b/tests/harness.js @@ -22,7 +22,7 @@ function split(html) { let s = SPLIT.get(html); if (s) return s; const code = []; - const shell = html.replace(/'; }); diff --git a/tests/land-islands.test.js b/tests/land-islands.test.js index a52e6a1..a9cdbb8 100644 --- a/tests/land-islands.test.js +++ b/tests/land-islands.test.js @@ -6,12 +6,13 @@ const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const { load } = require('./harness'); +const { lit } = require('../scripts/lib/js-literal'); 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', () => { 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=[]; 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)});})()`)); diff --git a/tests/pie-backhaul.test.js b/tests/pie-backhaul.test.js index 934ed2e..ea88613 100644 --- a/tests/pie-backhaul.test.js +++ b/tests/pie-backhaul.test.js @@ -5,6 +5,7 @@ const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); 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 // 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', () => { const { ev, errors } = load(); 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); const out = () => ev("JSON.stringify([R.served,R.demand,R.egT,R.load,R.l2,R.l2lat,R.citySrv])"); const a = out(); diff --git a/tests/pie-balance.test.js b/tests/pie-balance.test.js index 05f4c39..ecb1c1a 100644 --- a/tests/pie-balance.test.js +++ b/tests/pie-balance.test.js @@ -9,6 +9,7 @@ const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const { load } = require('./harness'); +const { lit } = require('../scripts/lib/js-literal'); 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) { const g = load({ seed }); 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'}); 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); diff --git a/tests/pie-routing.test.js b/tests/pie-routing.test.js index 40043fe..1374565 100644 --- a/tests/pie-routing.test.js +++ b/tests/pie-routing.test.js @@ -5,6 +5,7 @@ const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); 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 // 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', () => { const { ev, errors } = load(); 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); const out = () => ev("JSON.stringify([R.served,R.demand,R.revMo,R.egT,R.load,R.l2,R.l2lat,R.rev])"); const a = out(); diff --git a/tests/pie-traffic.test.js b/tests/pie-traffic.test.js index 5faa9cd..633de79 100644 --- a/tests/pie-traffic.test.js +++ b/tests/pie-traffic.test.js @@ -5,6 +5,7 @@ const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); 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. 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', () => { const { ev, errors } = load(); 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("trSkyList().length"), 0); assert.equal(ev("pieFiberMs({k:'c',id:'x'})"), Infinity);