0.2.6-dev: the maintainer's decisions of 2026-10-12 — the 玩法说明 pages' WebP copies are lossy at quality 90 (25.6 MB of PNG → 4.2 MB; lossless stays a GUIDE_WEBP_MODE away) and /healthz?traffic=1 answers the counters to a loopback or private-network client only (a public visitor, also one a local tunnel or proxy forwards, gets the plain report; TRUST_PROXY applies as for the WebSocket limits); golden: unchanged

This commit is contained in:
sganggs committed 2026-10-12 19:09:54 +08:00
1 parent 35f4895219
commit 79bb26b317
10 files changed
+71 -26

No files matched your search

+11 -6
View File
@@ -210,11 +210,11 @@ print(json.dumps(e.prefab_node(go)))`);
assert.equal(raw.stdout.trim(), '[0.0, 0, 0.0]');
});
test('guide pages (host bandwidth layer 0): --webp writes a lossless WebP copy of every page PNG, the manifest lists it, the PNG stays',
test('guide pages (host bandwidth layer 0): --webp writes a WebP copy of every page PNG (lossy q90 by default, lossless on request), the manifest lists it, the PNG stays',
{ skip: spawnSync(PY, ['-c', "import sys; from PIL import features; sys.exit(0 if features.check('webp') else 1)"], { env: ENV }).status !== 0 && 'no Pillow with WebP' }, () => {
const jobs = JSON.parse(spawnSync(PY, [path.join(TOOL, 'extract.py'), '--print-jobs'], { encoding: 'utf8', env: ENV }).stdout);
assert.deepEqual(jobs.guideWebp.sub, 'guide');
assert.equal(jobs.guideWebp.mode, 'lossless', 'lossy pages wait for the maintainer\'s comparison');
assert.equal(jobs.guideWebp.mode, 'lossy', 'quality 90, the maintainer\'s choice of 2026-10-12');
assert.ok(!jobs.webp.some((w) => w.sub === 'guide'), 'the board texture table is unchanged');
const out = py(`
import tempfile, pathlib
@@ -235,20 +235,25 @@ mf.write_text(json.dumps({'version': 1, 'source': 'local-client', 'count': 4, 'g
code = e.webp_only(root, mf, lambda *a: None)
doc = json.loads(mf.read_text())
g = doc['groups']['guide']
modes = {k: v.get('webp') for k, v in g.items()}
px = lambda p: list(Image.open(p).convert('RGBA').getdata())
print(json.dumps({'code': code, 'paths': {k: v['path'] for k, v in g.items()}, 'modes': {k: v.get('webp') for k, v in g.items()},
e.GUIDE_WEBP_MODE = 'lossless'
again = e.run_webp(root, 'guide', doc['groups'], lambda *a: None)
print(json.dumps({'code': code, 'paths': {k: v['path'] for k, v in g.items()}, 'modes': modes,
'relisted': {k: v.get('webp') for k, v in g.items()},
'other': doc['groups']['ui/battle']['x']['path'],
'same': all(px(sub / f'{n}.png') == px(sub / f'{n}.webp') for n in ['autochess_home_1', 'autochess_shop_2']),
'png': all((sub / f'{n}.png').exists() for n in ['autochess_home_1', 'autochess_shop_2']),
'again': e.run_webp(root, 'guide', doc['groups'], lambda *a: None)}))`);
'again': again}))`);
assert.equal(out.code, 0);
const at = (n, ext) => `/assets/local/guide/${n}.${ext}`;
assert.deepEqual(out.paths, { autochess_home_1: at('autochess_home_1', 'webp'), autochess_shop_2: at('autochess_shop_2', 'webp'), autochess_handbook_9: at('autochess_handbook_9', 'png') });
assert.deepEqual(out.modes, { autochess_home_1: 'lossless', autochess_shop_2: 'lossless', autochess_handbook_9: null });
assert.deepEqual(out.modes, { autochess_home_1: 'lossy', autochess_shop_2: 'lossy', autochess_handbook_9: null });
assert.equal(out.other, '/assets/local/ui/battle/x.png', 'other groups keep their PNGs');
assert.ok(out.same, 'lossless: the same pixels, alpha included');
assert.ok(out.png, 'the PNG stays beside the copy');
assert.equal(out.again, 2, 'a second run (another GUIDE_WEBP_MODE) rewrites the copies the manifest already lists');
assert.deepEqual(out.relisted, { autochess_home_1: 'lossless', autochess_shop_2: 'lossless', autochess_handbook_9: null });
assert.ok(out.same, 'lossless: the same pixels, alpha included');
});
});
+32
View File
@@ -103,3 +103,35 @@ test('the counter on its own: a string body in another encoding, an aborted resp
assert.equal(ws.payloadIn, 7);
assert.equal(tc.snapshot().seconds, 0);
});
test('/healthz?traffic=1 answers the counters to a loopback / LAN client only (maintainer, 2026-10-12)', async () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'sp-traffic-lan-'));
fs.mkdirSync(path.join(tmp, 'public'), { recursive: true });
fs.mkdirSync(path.join(tmp, 'data'), { recursive: true });
fs.mkdirSync(path.join(tmp, 'shared'), { recursive: true });
fs.writeFileSync(path.join(tmp, 'public/index.html'), '<!doctype html><p>hi</p>');
const dirs = { publicDir: path.join(tmp, 'public'), dataDir: path.join(tmp, 'data'), sharedDir: path.join(tmp, 'shared') };
const has = async (port, headers) => {
const r = await get(port, '/healthz?traffic=1', headers);
assert.equal(r.status, 200);
const body = JSON.parse(r.body);
assert.equal(body.ok, true, 'the plain report still answers');
return 'traffic' in body;
};
const auto = await startServer({ port: 0, host: '127.0.0.1', quiet: true, ...dirs });
try {
assert.equal(await has(auto.port), true, 'the host itself (loopback)');
assert.equal(await has(auto.port, { 'x-forwarded-for': '192.168.1.20' }), true, 'a LAN client behind a local proxy');
assert.equal(await has(auto.port, { 'x-forwarded-for': '100.101.102.103' }), true, 'a virtual-LAN (CGNAT range) address');
assert.equal(await has(auto.port, { 'x-forwarded-for': '203.0.113.9' }), false, 'a public visitor through a tunnel / proxy on this machine');
assert.equal(await has(auto.port, { 'cf-connecting-ip': '2001:db8::7' }), false, 'a public IPv6 visitor through cloudflared');
} finally {
await auto.close();
}
const ignore = await startServer({ port: 0, host: '127.0.0.1', quiet: true, trustProxy: false, ...dirs });
try {
assert.equal(await has(ignore.port, { 'x-forwarded-for': '203.0.113.9' }), true, 'TRUST_PROXY=0: the loopback peer itself counts');
} finally {
await ignore.close();
}
});