Phone UI and touch precision overhaul, proxy fixes, Orbital Uplink, four new maps

Phone panels (reviewed + QA'd, matrix of 22 layouts with real taps/bounding boxes):
- selected-tower action bar over the board (Upgrade/Sell/Target/close), info panel
  updated in place so taps are never lost, scrollable palette for 7+ towers,
  overlays with pinned footers (Help "Got it", Play solo, Join always visible),
  tappable room chip to invite, reduced-motion/contrast/forced-colors fixes,
  paused state, partner cursor labels, bigger level pips and owner flags
- touch input rewritten around "pointerdown commits nothing": pinch never builds,
  10px tap slop, palm-proof pinch, long-press pings with any tool armed, nudge
  arrows for precise placement, hotkey repeat guard, proportional wheel zoom
- new e2e: select/sell, info-panel stability, UI states, touch precision;
  camera unit tests

Proxy/server (reproduced against real nginx 1.26 with NPM v2.16 config):
- Origin check works when the proxy drops a non-default port, TRUSTED_PROXIES for
  proxies on global IPv6/CGNAT addresses, service worker no longer serves nginx's
  502 page, DEPLOY.md corrected (NPM default read timeout is 90 s, Advanced-tab
  limits, path-prefix, cookie size, per-IP cap behaviour)

Content:
- Orbital Uplink: 4-level endgame tower (450 + 500/800/1200 credits): piercing
  armour-ignoring beam, blast and lingering slow, ground+air, range 11-14;
  glyph, beam effect, sound, help text, unit tests
- Maps: The Canyon, Archipelago, Fortress, Pinwheel (7 maps total)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
This commit is contained in:
Claude 2026-10-10 18:03:24 +00:00
parent dad0382e10
commit a5bd09d505
22 changed files with 2423 additions and 405 deletions

101
test/camera.test.js Normal file
View file

@ -0,0 +1,101 @@
'use strict';
// The camera math of the renderer (cell <-> screen under rotation, zoom and pan) is what turns a fingertip into a cell. It runs in Node
// here with a stub canvas: randomised round trips, so a rotated board, a zoomed board and a panned board all pick the same cell the
// player sees. (public/js/render.js assigns to `this` when there is no `self`, i.e. to module.exports in Node.)
const test = require('node:test');
const assert = require('node:assert/strict');
const TD = require('../public/js/sim.js');
const NW = require('../public/js/render.js').NW;
function rng(seed) { let s = seed >>> 0; return () => { s = (s * 1664525 + 1013904223) >>> 0; return s / 4294967296; }; }
const stubCanvas = { getContext() { return {}; }, width: 0, height: 0 };
function makeRenderer(mapId, rot, W, H) {
const r = new NW.Renderer(stubCanvas);
r.setBoard(new TD.Board(mapId));
r.setRotation(rot);
r.resize(W, H, 1);
return r;
}
function randomCamera(r, rand) {
r.setZoom(1 + rand() * 3, rand() * r.W, rand() * r.H); // zoom about a random point ...
r.panBy((rand() - 0.5) * r.W * 1.5, (rand() - 0.5) * r.H * 1.5); // ... then pan (the camera clamps what is too far)
}
const DIRS = [[-1, 0], [1, 0], [0, -1], [0, 1]];
test('every cell round-trips through the screen, and a point anywhere inside a cell picks it (rotated or not, zoomed, panned)', () => {
const rand = rng(20261010);
let checked = 0;
for (const mapId of TD.MAP_ORDER) {
for (const rot of [false, true]) {
for (let run = 0; run < 6; run++) {
const W = 280 + Math.floor(rand() * 700), H = 200 + Math.floor(rand() * 700);
const r = makeRenderer(mapId, rot, W, H);
if (run) randomCamera(r, rand);
const cs = r.cellSizePx(), b = r.board;
for (let y = 0; y < b.rows; y++) for (let x = 0; x < b.cols; x++) {
const s = r.cellToScreen(x, y);
const c = r.screenToCell(s.x, s.y);
assert.deepEqual([c.x, c.y], [x, y], `${mapId} rot=${rot} ${W}x${H} zoom=${r.zoom.toFixed(2)}: cell ${x},${y} came back as ${c.x},${c.y}`);
for (let k = 0; k < 3; k++) {
const o = r.screenToCell(s.x + (rand() - 0.5) * 0.9 * cs, s.y + (rand() - 0.5) * 0.9 * cs);
assert.deepEqual([o.x, o.y], [x, y], `${mapId} rot=${rot}: a point inside cell ${x},${y} picked ${o.x},${o.y}`);
}
checked++;
}
}
}
}
assert.ok(checked > 3000);
});
test('zooming keeps the point under the finger fixed', () => {
const rand = rng(7);
let checked = 0;
for (const rot of [false, true]) {
for (let run = 0; run < 120; run++) {
const r = makeRenderer('open', rot, 300 + rand() * 500, 300 + rand() * 500);
randomCamera(r, rand);
const ax = rand() * r.W, ay = rand() * r.H, before = r._s2w(ax, ay);
r.setZoom(r.zoom * (0.6 + rand() * 1.6), ax, ay);
const after = r._s2w(ax, ay);
// The camera refuses to keep it exactly where it clamps the pan: a board smaller than the canvas is centred, and a big one may
// not be dragged more than 24 px past its edge. Only the free case is checked.
const d = r._dims(), sw = d.w * r.scale, sh = d.h * r.scale;
const free = sw > r.W && sh > r.H && Math.abs(r.cam.px) < (sw - r.W) / 2 + 23.9 && Math.abs(r.cam.py) < (sh - r.H) / 2 + 23.9;
if (!free) continue;
checked++;
assert.ok(Math.hypot(after.x - before.x, after.y - before.y) < 0.01, `rot=${rot}: the world point under (${ax.toFixed(1)},${ay.toFixed(1)}) moved by ${Math.hypot(after.x - before.x, after.y - before.y).toFixed(3)}`);
}
}
assert.ok(checked > 40, 'only ' + checked + ' unclamped runs');
});
test('stepCell moves exactly one cell in a SCREEN direction, also when the board is drawn turned 90 degrees', () => {
const rand = rng(99);
for (const rot of [false, true]) {
for (let run = 0; run < 10; run++) {
const r = makeRenderer('open', rot, 320 + rand() * 400, 320 + rand() * 400);
if (run % 2) randomCamera(r, rand);
const b = r.board, cs = r.cellSizePx();
for (let k = 0; k < 40; k++) {
const x = 1 + Math.floor(rand() * (b.cols - 2)), y = 1 + Math.floor(rand() * (b.rows - 2));
const s0 = r.cellToScreen(x, y);
for (const [dx, dy] of DIRS) {
const n = r.stepCell(x, y, dx, dy), s1 = r.cellToScreen(n.x, n.y);
assert.ok(Math.abs(s1.x - s0.x - dx * cs) < 1e-6 && Math.abs(s1.y - s0.y - dy * cs) < 1e-6, `rot=${rot}: step (${dx},${dy}) from ${x},${y} moved the cell by (${(s1.x - s0.x).toFixed(2)},${(s1.y - s0.y).toFixed(2)}) instead of (${dx * cs},${dy * cs})`);
}
}
}
}
});
test('at zoom 1 the whole board, with its margin, is inside the canvas (a tap on any edge cell is on screen)', () => {
const rand = rng(5);
for (const mapId of TD.MAP_ORDER) for (const rot of [false, true]) {
const W = 300 + Math.floor(rand() * 600), H = 300 + Math.floor(rand() * 600), r = makeRenderer(mapId, rot, W, H), b = r.board, h = r.cellSizePx() / 2;
for (const [x, y] of [[0, 0], [b.cols - 1, 0], [0, b.rows - 1], [b.cols - 1, b.rows - 1]]) {
const s = r.cellToScreen(x, y);
assert.ok(s.x - h >= -0.01 && s.y - h >= -0.01 && s.x + h <= W + 0.01 && s.y + h <= H + 0.01, `${mapId} rot=${rot} ${W}x${H}: corner cell ${x},${y} is cut off`);
}
}
});

View file

@ -1156,6 +1156,143 @@ test('per-IP socket cap uses X-Forwarded-For behind a private/loopback peer; 429
});
});
// ================================================================ proxy findings (docs/review-2026-10-09, proxy-*)
test('Origin check: a trusted proxy that drops the port from Host (nginx $host, nginx Proxy Manager) on a non-default public port', () => {
const req = (h, peer) => ({ headers: h, socket: { remoteAddress: peer || '10.0.0.2' } });
const o = { trustProxy: 'auto', allowedOrigins: [] };
// https://game.example.com:8443 -> proxy -> Host: game.example.com (no port), Origin keeps :8443
const stripped = { host: 'game.example.com', origin: 'https://game.example.com:8443' };
assert.equal(netx.originAllowed(req(stripped), o), true, 'private proxy peer');
assert.equal(netx.originAllowed(req(stripped, '::ffff:127.0.0.1'), o), true, 'loopback proxy peer');
assert.equal(netx.originAllowed(req({ host: 'game.example.com', origin: 'http://GAME.example.com:8080' }), o), true, 'http on 8080');
assert.equal(netx.originAllowed(req({ host: 'game.example.com', origin: 'https://game.example.com' }), o), true, 'default port still works');
// ...and must stay closed everywhere else
assert.equal(netx.originAllowed(req(stripped, '203.0.113.9'), o), false, 'public peer is not a proxy: Host must match exactly');
assert.equal(netx.originAllowed(req(stripped), { trustProxy: false, allowedOrigins: [] }), false, 'TRUST_PROXY=0');
assert.equal(netx.originAllowed(req(stripped, '203.0.113.9'), { trustProxy: true, allowedOrigins: [] }), true, 'TRUST_PROXY=1 believes any peer');
assert.equal(netx.originAllowed(req({ host: 'game.example.com', origin: 'https://evil.example.com:8443' }), o), false, 'another host name');
assert.equal(netx.originAllowed(req({ host: 'game.example.com', origin: 'https://game.example.com.evil.net:8443' }), o), false, 'name suffix trick');
assert.equal(netx.originAllowed(req({ host: 'game.example.com:8080', origin: 'https://game.example.com:8443' }), o), false,
'Host WITH a port (a direct connection, or a proxy that keeps it) must match exactly');
assert.equal(netx.originAllowed(req({ host: '127.0.0.1:8080', origin: 'http://127.0.0.1:9999' }, '127.0.0.1'), o), false, 'direct loopback, other port');
assert.equal(netx.originAllowed(req({ host: 'game.example.com' }), o), true, 'no Origin');
assert.equal(netx.originAllowed(req({ host: '[2001:db8::7]', origin: 'https://[2001:db8::7]:8443' }), o), true, 'IPv6 literal');
assert.equal(netx.originAllowed(req({ host: '[2001:db8::7]', origin: 'https://[2001:db8::8]:8443' }), o), false, 'other IPv6 literal');
assert.equal(netx.hostParts('Game.Example.com:8443').port, '8443');
assert.equal(netx.hostParts('https://game.example.com:443').port, '');
assert.equal(netx.hostParts('a b'), null);
});
test('Origin check over a real upgrade: Host without port + Origin with port is accepted from a trusted proxy peer only', async () => {
await withServer({}, async (S) => { // the test peer is loopback = a trusted proxy under auto
const ok = (host, origin) => probe(S.url, { headers: { Host: host }, origin });
assert.equal((await ok('highport.test', 'https://highport.test:8332')).ok, true);
assert.equal((await ok('highport.test', 'http://highport.test:8330')).ok, true);
assert.equal((await ok('highport.test', 'https://evil.test:8332')).status, 403);
assert.equal((await ok('highport.test:8330', 'https://highport.test:8332')).status, 403, 'Host has a port: exact match only');
});
await withServer({ trustProxy: false }, async (S) => {
assert.equal((await probe(S.url, { headers: { Host: 'highport.test' }, origin: 'https://highport.test:8332' })).status, 403);
});
});
test('TRUSTED_PROXIES: parseTrustedProxies accepts IPs and CIDRs (v4 + v6) and rejects typos', () => {
const t = netx.parseTrustedProxies(' 100.64.0.0/10, 2001:db8::6 ,2001:db8:1::/48,,192.0.2.1 ');
assert.deepEqual(t.list, ['100.64.0.0/10', '2001:db8::6', '2001:db8:1::/48', '192.0.2.1']);
for (const ip of ['100.64.1.1', '100.127.255.254', '::ffff:100.64.0.1', '2001:db8::6', '2001:DB8::6', '2001:db8:1:ffff::9', '192.0.2.1'])
assert.equal(t.has(ip), true, ip);
for (const ip of ['100.63.255.255', '100.128.0.1', '2001:db8::7', '2001:db8:2::1', '192.0.2.2', '8.8.8.8', 'junk', ''])
assert.equal(t.has(ip), false, ip);
assert.deepEqual(netx.parseTrustedProxies(['10.1.1.1', '2001:db8::/32']).list, ['10.1.1.1', '2001:db8::/32']);
for (const v of [undefined, null, '', ' , ', []]) assert.equal(netx.parseTrustedProxies(v), null);
for (const bad of ['nonsense', '100.64.0.0/33', '2001:db8::/129', '1.2.3.4/', '1.2.3.4/x', '1.2.3', '::ffff:10.0.0.0/104', '100.64.0.0/10, oops'])
assert.throws(() => netx.parseTrustedProxies(bad), /invalid TRUSTED_PROXIES entry/, bad);
});
test('TRUSTED_PROXIES: a proxy on a global IPv6 / CGNAT address is believed (isTrustedPeer, clientIp, Origin) once it is listed', async () => {
const req = (peer, h) => ({ headers: h || {}, socket: { remoteAddress: peer } });
const xff = { 'x-forwarded-for': '198.51.100.7' };
const t = netx.parseTrustedProxies('100.64.0.0/10,2001:db8::6');
// before: the built-in private list does not know these addresses, every player is "the proxy"
assert.equal(netx.clientIp(req('2001:db8::6', xff), 'auto'), '2001:db8::6');
assert.equal(netx.clientIp(req('100.64.1.1', xff), 'auto'), '100.64.1.1');
assert.equal(netx.isTrustedPeer(req('2001:db8::6'), 'auto'), false);
// after
assert.equal(netx.clientIp(req('2001:db8::6', xff), 'auto', t), '198.51.100.7');
assert.equal(netx.clientIp(req('::ffff:100.64.1.1', xff), 'auto', t), '198.51.100.7');
assert.equal(netx.isTrustedPeer(req('2001:db8::6'), 'auto', t), true);
assert.equal(netx.clientIp(req('2001:db8::7', xff), 'auto', t), '2001:db8::7', 'an unlisted neighbour is still not believed');
assert.equal(netx.clientIp(req('203.0.113.5', xff), 'auto', t), '203.0.113.5');
assert.equal(netx.clientIp(req('10.0.0.2', xff), 'auto', t), '198.51.100.7', 'the private ranges stay trusted: the list is an addition');
assert.equal(netx.clientIp(req('2001:db8::6', xff), false, t), '2001:db8::6', 'TRUST_PROXY=0 wins over the list');
assert.equal(netx.clientIp(req('2001:db8::6', xff), true), '198.51.100.7');
const o = { trustProxy: 'auto', allowedOrigins: [], trustedProxies: t };
const fwd = { host: 'x', origin: 'https://c.d', 'x-forwarded-host': 'c.d' };
assert.equal(netx.originAllowed(req('2001:db8::6', fwd), { trustProxy: 'auto', allowedOrigins: [] }), false);
assert.equal(netx.originAllowed(req('2001:db8::6', fwd), o), true, 'X-Forwarded-Host from a listed proxy');
assert.equal(netx.originAllowed(req('2001:db8::6', { host: 'game.example.com', origin: 'https://game.example.com:8443' }), o), true);
assert.equal(netx.originAllowed(req('2001:db8::7', { host: 'game.example.com', origin: 'https://game.example.com:8443' }), o), false);
// the server option: bad list stops the start, a good one is kept
await assert.rejects(createServer({ port: 0, host: '127.0.0.1', log: noop, trustedProxies: '100.64.0.0/40' }), /invalid TRUSTED_PROXIES entry/);
await withServer({ trustedProxies: '100.64.0.0/10, 2001:db8::6' }, async (S) => {
assert.deepEqual(S.srv.options.trustedProxies.list, ['100.64.0.0/10', '2001:db8::6']);
assert.equal((await probe(S.url, { headers: { 'X-Forwarded-For': '198.51.100.7' } })).ok, true);
});
});
// public/sw.js run in a vm with a fake Cache Storage, to see what a navigation gets while nginx answers 502 for a stopped app
function loadServiceWorker(net) {
const vm = require('vm');
const src = fs.readFileSync(path.join(__dirname, '..', 'public', 'sw.js'), 'utf8');
const BASE = 'https://game.test/';
const handlers = {}, store = new Map(), puts = [];
store.set(BASE, R(200, 'cached game')); store.set(BASE + 'index.html', R(200, 'cached shell'));
store.set(BASE + 'js/main.js', R(200, 'cached main.js'));
const caches = {
match: async (r) => store.get(typeof r === 'string' ? new URL(r, BASE + 'sw.js').href : r.url),
open: async () => ({ put: async (r, res) => { puts.push(r.url + ' ' + res.status); store.set(r.url, res); }, addAll: async () => {} }),
keys: async () => [], delete: async () => true,
};
const self = { location: new URL(BASE + 'sw.js'), skipWaiting() {}, clients: { claim() {} }, addEventListener: (t, f) => { handlers[t] = f; } };
vm.runInNewContext(src, { self, caches, fetch: net, URL, Response, Promise, Set, console });
return {
BASE, puts,
async get(url, mode) {
let out; const request = { method: 'GET', url, mode: mode || 'no-cors' };
handlers.fetch({ request, respondWith: (p) => { out = p; } });
const res = await out;
await new Promise((r) => setImmediate(r)); // the cache.put is fire-and-forget
return res;
},
};
}
function R(status, body) { return { status, body, ok: status >= 200 && status < 300, type: 'basic', clone() { return R(status, body); } }; }
test('service worker: 502/503/504 from the proxy fall back to the cache instead of showing nginx\'s error page', async () => {
for (const code of [502, 503, 504]) {
const sw = loadServiceWorker(async () => R(code, 'nginx error page'));
const B = sw.BASE;
assert.equal((await sw.get(B, 'navigate')).body, 'cached game', code + ': cached page, not the proxy error page');
assert.equal((await sw.get(B + '?room=ABCD', 'navigate')).body, 'cached shell', code + ': invite link -> cached app shell');
assert.equal((await sw.get(B + 'js/main.js')).body, 'cached main.js', code + ': cached script');
assert.equal((await sw.get(B + 'assets/music/battle.mp3')).status, code, code + ': never cached -> the real error, not index.html');
assert.deepEqual(sw.puts, [], code + ': an error response is never stored');
}
const down = loadServiceWorker(async () => { throw new TypeError('Failed to fetch'); });
assert.equal((await down.get(down.BASE, 'navigate')).body, 'cached game', 'network failure: cached page (unchanged behaviour)');
assert.equal((await down.get(down.BASE + '?room=ABCD', 'navigate')).body, 'cached shell');
assert.equal((await down.get(down.BASE + 'assets/music/battle.mp3')).type, 'error', 'a missing file is a network error, not index.html');
});
test('service worker: only complete 200 responses are cached (not a 206 range response, not a 404)', async () => {
const sw = loadServiceWorker(async (r) => R(r.url.endsWith('/range.mp3') ? 206 : r.url.endsWith('/missing.png') ? 404 : 200, 'fresh'));
const B = sw.BASE;
assert.equal((await sw.get(B + 'js/main.js')).body, 'fresh', 'healthy upstream: network first');
assert.equal((await sw.get(B + 'assets/range.mp3')).status, 206, 'a range response is passed through');
assert.equal((await sw.get(B + 'missing.png')).status, 404, 'a 404 is the upstream\'s answer');
assert.deepEqual(sw.puts, [B + 'js/main.js 200'], 'only the complete 200 is cached (not 206, not 404)');
});
// ================================================================ dual stack
test('listenDual: IPv6 fallback logic (stub server)', async () => {
const stub = (failWith) => {

View file

@ -313,7 +313,7 @@ test('fuzz: garbage commands never throw', () => {
});
test('balance tables keep the shape the client and server rely on', () => {
assert.deepEqual(TD.TOWER_ORDER, ['wall', 'filter', 'ids', 'mortar', 'throttle', 'arc']);
assert.deepEqual(TD.TOWER_ORDER, ['wall', 'filter', 'ids', 'mortar', 'throttle', 'arc', 'uplink']);
assert.deepEqual(TD.ENEMY_ORDER, ['ping', 'worm', 'trojan', 'spam', 'ghost', 'rootkit']);
assert.equal(TOWERS.wall.levels.length, 1);
assert.ok(TOWERS.wall.refund, 'walls refund in full');
@ -321,13 +321,14 @@ test('balance tables keep the shape the client and server rely on', () => {
const t = TOWERS[k];
assert.ok(t.name && t.color && t.key && t.desc, k + ' has display fields');
if (k === 'wall') continue;
assert.equal(t.levels.length, 3, k + ' has exactly 3 levels');
assert.equal(t.levels.length, k === 'uplink' ? 4 : 3, k + ' has the expected number of levels');
t.levels.forEach((lv, i) => {
assert.ok(lv.cost > 0 && lv.range > 0, k + ' L' + (i + 1) + ' cost/range');
if (k === 'throttle') assert.ok(lv.slow > 0 && lv.slow <= 0.6, 'slow is capped at 0.6 by the sim');
else assert.ok(lv.dmg > 0 && lv.rate > 0, k + ' L' + (i + 1) + ' dmg/rate');
if (k === 'mortar') assert.ok(lv.splash > 0);
if (k === 'arc') assert.ok(lv.chains >= 1 && lv.chainRange > 0 && lv.falloff > 0 && lv.falloff < 1);
if (k === 'uplink') assert.ok(lv.width > 0 && lv.splash > 0 && lv.slowOnHit > 0 && lv.slowOnHit <= 0.6 && lv.slowFor > 0);
if (i > 0) assert.ok(lv.range >= t.levels[i - 1].range, 'range never shrinks on upgrade');
});
}
@ -347,3 +348,39 @@ test('balance tables keep the shape the client and server rely on', () => {
for (let n = 2; n <= 60; n++) assert.ok(TD.hpScale(n) > TD.hpScale(n - 1));
for (let n = 2; n <= 60; n++) assert.ok(TD.rewardScale(n) >= TD.rewardScale(n - 1));
});
test('Orbital Uplink: expensive endgame beam that pierces, ignores armour, blasts, slows and hits flyers', () => {
const s = new Sim({ map: 'open', gold: 100000 });
const r = s.place('uplink', 5, 7);
assert.ok(r.ok);
const t = s.towerById(r.id), st = TOWERS.uplink.levels[0];
const idsTotal = TOWERS.ids.levels.reduce((a, l) => a + l.cost, 0);
const upTotal = TOWERS.uplink.levels.reduce((a, l) => a + l.cost, 0);
assert.ok(TOWERS.uplink.levels[0].cost >= 5 * TOWERS.ids.levels[0].cost, 'buying it costs several times an IDS Sniper');
assert.ok(upTotal >= 8 * idsTotal, 'a fully upgraded Uplink costs many times a fully upgraded IDS');
assert.ok(st.range > TOWERS.ids.levels[2].range, 'it out-ranges even a level 3 IDS');
assert.ok(st.dmg > TOWERS.ids.levels[2].dmg, 'and hits harder than a level 3 IDS from the start');
const mk = (id, x, y, extra) => Object.assign({ id, kind: 'trojan', air: false, x, y, cx: 0, cy: 0, tx: -1, ty: -1, hp: 5000, maxhp: 5000, armor: 50, speed: 1, slow: 0, slowT: 0, slowAmt: 0, rem: 10, dead: false }, extra);
// tower centre is (5.5, 7.5): three monsters on the horizontal line, one flyer on it, one far off the line, one beside the first target
const a = mk(201, 8.5, 7.5), b = mk(202, 11.5, 7.5), c = mk(203, 14.5, 7.5), air = mk(204, 12.5, 7.5, { air: true, kind: 'ghost' });
const off = mk(205, 9.5, 12.5), near = mk(206, 8.5, 8.6);
s.monsters = [a, b, c, air, off, near];
t.mode = 'close'; t.cd = 0;
s.updateTower(t, TD.STEP);
for (const o of [a, b, c, air]) assert.equal(o.hp, 5000 - st.dmg, 'on-line monster took full beam damage ignoring armour (armour 50)');
assert.equal(off.hp, 5000, 'a monster off the line is untouched');
assert.equal(near.hp, 5000 - st.dmg * 0.5, 'a monster beside the target takes half from the blast, also ignoring armour');
assert.ok(a.slowT > 0 && a.slowAmt > 0, 'hit monsters are slowed');
assert.equal(off.slowT, 0);
// slow lingers after the shot and then wears off
t.cd = 1e9; // stop it re-firing so we can watch the slow wear off
s.tick(TD.STEP); assert.ok(a.slow > 0, 'slow is applied on the next tick');
for (let i = 0; i < 60 * 3; i++) s.tick(TD.STEP);
assert.equal(a.slow, 0, 'slow wears off after a couple of seconds');
// upgrades to level 4 and refunds 70% of everything spent
assert.ok(s.upgrade(t.id).ok); assert.ok(s.upgrade(t.id).ok); assert.ok(s.upgrade(t.id).ok);
assert.equal(s.upgrade(t.id).reason, 'max');
assert.equal(t.level, 4);
const g = s.gold; s.sell(t.id);
assert.equal(s.gold, g + Math.floor(upTotal * TD.SELL_RATIO));
});